-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow to loads undeclared field with meta attribute (fix #934) #957
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
Conversation
|
Why a duplicate fix for the same issue? Check my pull request over here: https://github.com/MongoEngine/mongoengine/pull/953/files#diff-e3e316e6686a3db66d2e679634f57f7f I think you might need to refactor a bit... This test fails on your branch: def test_undefined_field_allowed_read(self):
"""
Test read from data wtih undefined fields #934 #953
"""
class A(Document):
test = StringField(required=True)
test2 = StringField(required=True)
meta = {'collection': 'undefined_test'}
class B(Document):
test = StringField(required=True)
meta = {'collection': 'undefined_test', 'strict': True}
a = A()
a.test = 'one'
a.test2 = 'two'
a.save()
try:
b = B.objects.get()
self.assertEqual(b.test, a.test)
except Exception:
self.fail() |
|
Oh wait, nevermind... I see what you did. B() meta should set strict to False, my mistake. I pulled the test from my branch and replaced 'ignore_undefined_fields' with 'strict', not thinking about the logic being inverse. |
|
I submit the pull-request because I started it before you submitted yours and before I saw the discussion. Feel free to pick some code or documentation. Yeah, you should set By the way, you should avoid the following pattern: try:
# do whatever raises an exception
except Exception:
self.fail()Simply let the exception be catched by the testing framework. |
Indeed. Thanks. |
5 similar comments
|
I can definitely get behind this PR but I think there needs to be a discussion around this when we get ready to bump up to the next major version (0.10 or 1.0).
Thanks for the counter-example, this makes things more clear now! I still think there are some client side workarounds but I think it would be easier for both us the maintainers and users to add this option in for now and re-evaluate our options in the future. |
|
Great ! |
|
+1 |
|
👍 😜 |
|
👍 I am actually in favour of stricter validation, but this one seems to have impacted enough people ! |
This pull request try to fix #934 by adding an optionnal meta attribute:
strict.This attribute disable field existence check on data load, but not on constructor calls.
It also document both behaviors.