You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fix #620 has a bug. The key for changed_fields should not be field_name. It should use db_field.
When a ListField is missed in database and the field has a db_field is different than the field name, the default value check can put wrong field back to database. Then the database will no longer work.
It is better to take out whole block starting on 'elif field.default:', at line 713. Mongoengine should not change database silently.
The bug is in this code:
elif not only_fields or field_name in only_fields:
changed_fields.append(field_name)
test:
In old time you can have this:
class User(Document):
username = StringField(unique=True, db_field='unm')
password = StringField(db_field='pss')
…changing database
This resolved issue Please recall fix on: Saving document doesn't create new fields in existing collection MongoEngine#620MongoEngine#1126
iici-gli
added a commit
to iici-gli/mongoengine
that referenced
this issue
Oct 18, 2015
The fix #620 has a bug. The key for changed_fields should not be field_name. It should use db_field.
When a ListField is missed in database and the field has a db_field is different than the field name, the default value check can put wrong field back to database. Then the database will no longer work.
It is better to take out whole block starting on 'elif field.default:', at line 713. Mongoengine should not change database silently.
The bug is in this code:
elif not only_fields or field_name in only_fields:
changed_fields.append(field_name)
test:
In old time you can have this:
class User(Document):
username = StringField(unique=True, db_field='unm')
password = StringField(db_field='pss')
supper_name = User(username='admin', password='admin')
supper_name.save()
Then you may add some communication information to it:
class User(Document):
username = StringField(unique=True, db_field='unm')
password = StringField(db_field='pss')
communication_information_list = ListField(StringField(), db_field='com_ls')
new_user = User(username='a_user', password='auser', communication_information_list=
['phone: 234 765 1324', 'email: [email protected]'])
new_user.save()
load supper_user back
su = User.objects(username='admin').first()
print su._change_fields
You will see 'communication_information_list ' in changed list instead of 'com_ls'
change the password, then save, in database 'communication_information_list ' : null will be inserted
su.password = 'root'
su.save()
load it back, it will crash
su = User.objects(username='admin').first()
The text was updated successfully, but these errors were encountered: