-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
set attribute to None does not work (at least for fields with default values) #734
Comments
This has long been a bone of contention - I think you need to delete the value to remove it but that may have changed. Essentially, default means the value if its missing and not the value when first set - which is the issue. |
This is definately a bug. |
Copying comment from #735
|
When I set the value to None, I don't want to remove it - I want to set it to None but it does not happen |
…r fields with default values)
Here's the crux None is not a valid String, Number, EmbeddedDocument etc..
False If you set a StringField to None its string representation is "None" which is not correct. |
If it's required it should be null. |
|
In response:
So a couple more questions to help spec this out:
|
|
…r fields with default values). Solves MongoEngine#735 as well
It seems this could address #381 as well. |
…r fields with default values). Solves MongoEngine#735 as well
…r fields with default values). Solves MongoEngine#735 as well
Great! When will this be in a released version? |
Hi, I was playing with the new 'null' behavior, which I would like to use in a project I'm working on. While messing with it on master, I noticed some inconsistency in the behavior with regard to DateTimeField and ComplexDateTimeField. Here's a demonstration: def test_null_datetime_fields():
class TestDoc(Document):
dt_field = DateTimeField(null=True)
cdt_field = ComplexDateTimeField(null=True)
doc = TestDoc()
doc.save()
assert doc.dt_field is None
assert doc.cdt_field is None The cause seems to be related to some logic specific to ComplexDateTimeField that falls back to datetime.now on retrieval from db. I'm not sure what the motivation was for the different behavior between DateTimeField and ComplexDateTimeField -- it was introduced a long time ago and there's even a test to ensure it doesn't regress: I made a PR with a teeny patch that (I think) remedies the behavior: |
@DavidBord, has this issue been fixed? I use MongoEngine v0.10.0, but the nullable field will still be deleted if I set its value to None: class User(Document):
name = StringField(null=True)
user = User(name='user')
# the name field is stored in MongoDB
user.save()
user.name = None
# the name field is deleted from MongoDB
user.save() |
The text was updated successfully, but these errors were encountered: