Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated copyWith() for nested lists doesn't keep its inner child values #2192

Open
daniel-webstep opened this issue Apr 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@daniel-webstep
Copy link

daniel-webstep commented Apr 29, 2024

Describe the bug
When creating models that contains nested lists, the code generation for copyWith() doesn't keep track of the inner child. Instead, an empty list is returned. The toJson() works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. Create a class like
class: NestedLists
fields:
  doubleValue: double
  listDouble: List<double>
  listListDouble: List<List<double>>
  1. run serverpod generate
  2. Create the following tests
import 'dart:convert';

import 'package:example_server/src/generated/protocol.dart';
import 'package:test/test.dart';

void main() {
  NestedLists baseObject() {
    return NestedLists(doubleValue: 0, listDouble: [
      1
    ], listListDouble: [
      [2]
    ]);
  }

  group('NestedLists', () {
    test('toJson() returns a valid json for nested lists.', () {
      var obj = baseObject();
      var expectedJson = jsonDecode(
          '{"doubleValue": 0.0, "listDouble": [1.0], "listListDouble": [[2.0]]}');
      expect(obj.toJson(), equals(jsonDecode(expectedJson)));
    });
    test('copyWith() does return the same values.', () {
      var obj = baseObject();
      var expectedObj = baseObject();
      expect(obj.copyWith(), expectedObj);
    });
  });
}
  1. Run the tests
  2. See error

Expected behavior

Expected: _NestedListsImpl:<{"doubleValue":0.0,"listDouble":[1.0],"listListDouble":[[2.0]]}>
  Actual: _NestedListsImpl:<{"doubleValue":0.0,"listDouble":[1.0],"listListDouble":[]}>

package:matcher                                          expect
package:example_server/src/test/nested_lists_test.dart 25:7  main.<fn>.<fn>

Serverpod versions

  • CLI Version: Serverpod version: 1.2.6
  • Library version: serverpod: 1.2.6

Platform information
Ubuntu 22.04.4 LTS through Docker.

@Isakdl Isakdl added the bug Something isn't working label Apr 29, 2024
@Isakdl
Copy link
Collaborator

Isakdl commented Apr 29, 2024

Thank you for the detailed report!

@bfemmer
Copy link

bfemmer commented May 17, 2024

I'll pick this one up to work on (I don't see a linked PR ... if anyone is already working this one, please let me know).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants