这是indexloc提供的服务,不要输入任何密码
Skip to content

Firestore map keys considered invalid when containing / characters #83

@a-shine

Description

@a-shine

Describe the bug
We often store mappings of document reference paths (as strings) to values inside documents.

e.g.

{
    'activityType': 'activityA',
    'agents': {'products/product-a': 5.0},
}

Using the native Firestore libraries, we encountered no issues writing Firestore maps inside our documents that contain / characters in the key string. This seemingly is allowed in Firestore documents but triggers the Invalid argument (path) exception when attempting to write a document containing the map using the library.

  Invalid argument (path): Paths can't be empty and must not contain '*~/[]'.: "products/product-a"
  package:dart_firebase_admin/src/google_cloud_firestore/path.dart 255:7          new _StringFieldMask
  package:dart_firebase_admin/src/google_cloud_firestore/path.dart 289:47         new FieldPath.from
  package:dart_firebase_admin/src/google_cloud_firestore/field_value.dart 391:44  _validateUserInput
  package:dart_firebase_admin/src/google_cloud_firestore/field_value.dart 369:9   _validateUserInput.<fn>
  package:collection/src/list_extensions.dart 122:13                              ListExtensions.forEachIndexed
  package:dart_firebase_admin/src/google_cloud_firestore/field_value.dart 368:13  _validateUserInput
  package:dart_firebase_admin/src/google_cloud_firestore/field_value.dart 384:9   _validateUserInput
  package:dart_firebase_admin/src/google_cloud_firestore/write_batch.dart 293:3   _validateDocumentData
  package:dart_firebase_admin/src/google_cloud_firestore/write_batch.dart 158:5   WriteBatch.set
  package:dart_firebase_admin/src/google_cloud_firestore/reference.dart 301:54    DocumentReference.set
  test/data/services/firestore_api_service_test.dart 379:54                       main.<fn>.<fn>

To Reproduce

   await firestore.doc("activities/new-activity").set({
        'activityType': 'activityA',
        'agents': {'products/product-a': 5.0}
      });

Expected behavior
This should be a valid document and written to Firestore with the string key "products/product-a" in the document's list of product -> value mappings.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions