Skip to content

[DataConnect] Incorrect generated code for enum lists in dart/flutter. #9391

Closed

Description

@isenbj

[REQUIRED] Environment info

firebase-tools: 14.22.0

system: MacOS

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

enum Role {
  ADMIN
  ADJUSTER
  MANAGER
  DEVELOPER
}

type Member  @table {
    email: String! @col(dataType: "varchar(255)")
    firstName: String!
    lastName: String!
    phone: String
    roles: [Role!]
}

firebase dataconnect:sdk:generate

Generated code for a mutation that accepts a list of roles to update:

mutation UpdateProfile(
  # Basic profile information
  $email: String!
  $firstName: String!
  $lastName: String!
  $phone: String
  $roles: [Role!]
) @auth(level: USER) {
  # Step 2: Update member with provided fields
  member_upsert(
    data: {
      id_expr: "auth.uid"
      email: $email
      firstName: $firstName
      lastName: $lastName
      phone: $phone
      roles: $roles
    }
  )
}
    roles = Optional.optional(listDeserializer((data) => Role.values.byName(data)), listSerializer(enumSerializer));
    roles.value = json['roles'] == null ? null : (json['roles'] as List<dynamic>)
        .map((e) => Roles.fromJson(e))
        .toList();

There is no fromJson for enum. Either that should be generated, or firstWhere should be used

.map((e) => Role.values.firstWhere( (element) => element.name == e))

[REQUIRED] Actual behavior

Invalid Dart code

Activity

  1. google-oss-bot commented on Oct 27, 2025

    @google-oss-bot
    Collaborator

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. added
    api: dataconnect
    on Oct 27, 2025
  3. aalej commented on Oct 28, 2025

    @aalej
    Contributor

    Thanks @isenbj for the detailed report! I am able to reproduce the issue. As you mentioned, the generated SDK has an error. I'll raise this to our engineering team and mark this as reproducible.

    Sharing an mcve here.

  4. self-assigned this
    on Oct 28, 2025
  5. isenbj commented on Nov 13, 2025

    @isenbj
    Author

    Any updates?

  6. aalej commented on Nov 20, 2025

    @aalej
    Contributor

    Hey @isenbj there seems to be a fix for this in v14.23.0, could you give this version a try?

  7. added
    Needs: Author Feedback
    on Nov 20, 2025
  8. isenbj commented on Nov 20, 2025

    @isenbj
    Author

    I've tried using the shared mcve above and it still generates incorrectly:

    Image Image
  9. added and removed
    Needs: Author Feedback
    on Nov 20, 2025
  10. aalej commented on Nov 20, 2025

    @aalej
    Contributor

    It looks like we may be missing a type cast there, will follow up with our engineering team

  11. aalej commented on Nov 21, 2025

    @aalej
    Contributor

    A fix has been shipped in firebase-tools v14.26.0. I've tested the generated Dart SDK using the mcve and it no longer throws any errors. Could you give this latest version a try?

  12. added
    Needs: Author Feedback
    and removed on Nov 21, 2025
  13. isenbj commented on Nov 21, 2025

    @isenbj
    Author

    Looks good! Thank you for the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs: Author Feedbackapi: dataconnectreproducibletype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions