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

TypeError: Not a cmessage when calling document.set() #940

Closed
jstray opened this issue Jul 24, 2024 · 4 comments
Closed

TypeError: Not a cmessage when calling document.set() #940

jstray opened this issue Jul 24, 2024 · 4 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@jstray
Copy link

jstray commented Jul 24, 2024

This seems to be closely related to issue 778 and issue 680.

Getting TypeError: Not a cmessage on 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 which seemed to break this, everything worked before. Unfortunately I don't have that log so can't say exactly what upgraded.
Deprecating urllib3 to 1.26.15 (as suggested here) was no help

Stack Trace

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(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

document_path = 'projects/prc-dev/databases/(default)/documents/users/never_sent_any_missing'
document_data = {'timestamp': Sentinel: Value used to set a document field to the server timestamp., 'user_id': 'never_sent_any_missing'}

    def pbs_for_set_no_merge(document_path, document_data) -> List[types.write.Write]:
        """Make ``Write`` protobufs for ``set()`` methods.
    
        Args:
            document_path (str): A fully-qualified document path.
            document_data (dict): Property names and values to use for
                replacing a document.
    
        Returns:
            List[google.cloud.firestore_v1.types.Write]: One
            or two ``Write`` protobuf instances for ``set()``.
        """
        extractor = DocumentExtractor(document_data)
    
        if extractor.deleted_fields:
            raise ValueError(
                "Cannot apply DELETE_FIELD in a set request without "
                "specifying 'merge=True' or 'merge=[field_paths]'."
            )
    
        set_pb = extractor.get_update_pb(document_path)
    
        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

Environment details

  • OS type and version: MacOS 15.5
  • Python version: 3.12.4
  • pip version: 24.0
  • google-cloud-firestore version: 2.17.0
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Jul 24, 2024
@jstray
Copy link
Author

jstray commented Jul 24, 2024

Update: bug does not occur when I remove timestamp fields on the document I am trying to save, e.g. "timestamp" : firestore.SERVER_TIMESTAMP

@jstray
Copy link
Author

jstray commented Jul 24, 2024

Update: downgrading to protobuf 3.20.1 fixed the error

@ehsannas ehsannas assigned daniel-sanche and unassigned ehsannas Jul 26, 2024
@daniel-sanche
Copy link
Contributor

Thanks for the detailed feedback. It sounds like this error was due to a bad update for one of our dependencies, so I'm going to close for now. If anyone is still seeing this problem, let me know and I'll re-open

@mileslow
Copy link

this is still happening and it only happens in some cases

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

4 participants