MongoEngine / mongoengine

A Python Object-Document-Mapper for working with MongoDB
http://mongoengine.org
MIT License
4.24k stars 1.23k forks source link

Unable to Access Renamed Column 'woocomerce_id' in MongoEngine #2766

Closed kmikodev closed 1 year ago

kmikodev commented 1 year ago

Steps to Reproduce:

  1. Update the column name from 'ID' to 'woocomerce_id' in the 'Orders' collection using pymongo.
  2. Verify that all documents now have the 'woocomerce_id' property in the database.
  3. Use MongoEngine to retrieve and access the 'woocomerce_id' property from the 'Orders' collection.
  4. Observe the error message: "'Orders' object has no attribute 'woocomerce_id'".

Expected Behavior: The attribute 'woocomerce_id' should be accessible using the MongoEngine model 'Orders'.

Actual Behavior: Attempting to access 'woocomerce_id' using the MongoEngine model 'Orders' results in the mentioned error.

Additional Information:

Environment:

Code Snippets:

# Model definition in MongoEngine
class Orders(Document):
    woocomerce_id = StringField()
    # Other fields

# Accessing the property in the application
order_mongoengine = Orders.objects(id=id).first()
woocomerce_id_value = order_mongoengine.woocomerce_id  # This line triggers the error
bagerard commented 1 year ago

It is working fine with simple cases so probably there are additional things that makes this not working

image

Send an example of your pymongo documents that is failing + your actual Model/Document definition, there has to be some mismatches between the two.