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

firestore.Increment returns error: "TypeError: Not a cmessage" #778

Closed
akashrajkn opened this issue Oct 10, 2023 · 8 comments
Closed

firestore.Increment returns error: "TypeError: Not a cmessage" #778

akashrajkn opened this issue Oct 10, 2023 · 8 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Milestone

Comments

@akashrajkn
Copy link

akashrajkn commented Oct 10, 2023

Environment details

  • OS type and version: Ubuntu 22.04
  • Python version: 3.10.13
  • pip version: 23.2.1
  • google-cloud-firestore version: 2.11.0

Steps to reproduce

Run below code.

  • I've verified that duration is a float.
  • On firebase, total_duration field's type is Number

Relevant package versions

google-api-core==2.11.0
google-api-python-client==2.86.0
google-auth==2.17.3
google-auth-httplib2==0.1.0
google-cloud-core==2.3.2
google-cloud-firestore==2.11.0
google-cloud-storage==2.8.0
google-crc32c==1.5.0
google-resumable-media==2.4.1
googleapis-common-protos==1.59.0
proto-plus==1.22.2
protobuf==4.22.3
grpcio==1.58.0
grpcio-status==1.58.0

Code example

db = firestore.client()
doc_ref = db.collection(<collection_id>).document(<doc_id>)
doc_ref.update({'total_duration': firestore.Increment(duration)})

Stack trace

Traceback (most recent call last):
  File "/home/ubuntu/my_server/my_server/api/utils/firebase.py", line 238, in create_or_update_voice_profile_document
    doc_ref.update({'total_duration': firestore.Increment(duration)})
  File "/home/ubuntu/miniconda3/envs/server_env/lib/python3.10/site-packages/google/cloud/firestore_v1/document.py", line 324, in update
    batch, kwargs = self._prep_update(field_updates, option, retry, timeout)
  File "/home/ubuntu/miniconda3/envs/server_env/lib/python3.10/site-packages/google/cloud/firestore_v1/base_document.py", line 239, in _prep_update
    batch.update(self, field_updates, option=option)
  File "/home/ubuntu/miniconda3/envs/server_env/lib/python3.10/site-packages/google/cloud/firestore_v1/base_batch.py", line 141, in update
    write_pbs = _helpers.pbs_for_update(
  File "/home/ubuntu/miniconda3/envs/server_env/lib/python3.10/site-packages/google/cloud/firestore_v1/_helpers.py", line 941, in pbs_for_update
    update_pb.update_transforms.extend(field_transform_pbs)
TypeError: Not a cmessage
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Oct 10, 2023
@hansheng654
Copy link

exact same problem, nothing on internet helps. seems only few people like you and me getting this.
I tried chatgpt, it also pointed to this error. I first could not believe it, until I ran the exact code on the firebase official help doc, and it get the same error...... I just waste 2hour on bug from Google... maybe i should use dynamodb

@nielsbox
Copy link

Same also have this error and sometimes bumping the version of the library helps. But I'm already at latest now...

@hansheng654
Copy link

Now i am facing firestore.Increment function does nothing to the actual data field, and no error at all.
I expect better from Google.

@akashrajkn
Copy link
Author

@hansheng654 Based on this comment, I changed urllib3 package version to 1.26.15. After this, I don't get the above issue. Maybe this helps you?

@daniel-sanche daniel-sanche added this to the Q2 milestone Feb 23, 2024
@kolea2
Copy link
Contributor

kolea2 commented Apr 2, 2024

Hi @akashrajkn, thanks for filing this and providing an example. I tried this out with the latest version of the library (2.15.0) and was unable to reproduce this. Here's what I did:

document = db.collection("my-collection").document("number_doc")
f = float(1)
document.update({'num': firestore.Increment(f)})

I also tried different numbers, like 1.222 and was able to see the update successfully. Please let me know if you are still experiencing this issue after upgrading to the latest version. Thanks!

@kolea2 kolea2 assigned kolea2 and unassigned daniel-sanche Apr 2, 2024
@akashrajkn
Copy link
Author

@kolea2 Thanks for the reply! With version 2.15.0, I don't get the issue. Feel free to close this issue.

@kolea2 kolea2 closed this as completed Apr 3, 2024
@kolea2
Copy link
Contributor

kolea2 commented Apr 3, 2024

Awesome, thanks for confirming!

@jstray
Copy link

jstray commented Jul 24, 2024

Getting this same message, version 2.17.0, trying to execute this line:

db.collection("users").document(user_id).set(user_record)

Writing to the emulator, not the actual cloud. Recently did a pip install -r requirements.txt and it seemed to break this, worked before. Unfortunately I don't have that log so can't say exactly what upgraded.
Deprecating urllib3 to 1.26.15 was no help

message:

mailer_test.py:50: in create_test_data
    db.collection("users").document(user_id).set(user_record)
/usr/local/anaconda3/lib/python3.12/site-packages/google/cloud/firestore_v1/document.py:165: in set
    batch, kwargs = self._prep_set(document_data, merge, retry, timeout)
/usr/local/anaconda3/lib/python3.12/site-packages/google/cloud/firestore_v1/base_document.py:214: in _prep_set
    batch.set(self, document_data, merge=merge)
/usr/local/anaconda3/lib/python3.12/site-packages/google/cloud/firestore_v1/base_batch.py:112: in set
    write_pbs = _helpers.pbs_for_set_no_merge(

...
        if extractor.has_transforms:
            field_transform_pbs = extractor.get_field_transform_pbs(document_path)
>           set_pb.update_transforms.extend(field_transform_pbs)
E           TypeError: Not a cmessage

/usr/local/anaconda3/lib/python3.12/site-packages/google/cloud/firestore_v1/_helpers.py:723: TypeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Projects
None yet
Development

No branches or pull requests

6 participants