-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Check if undefined fields are supplied on document #457
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
|
Ok didn't read the contributing docs. Will look why these tests are failing, I hope it's not because they use undefined fields.... |
|
Will review for 0.9 as its a breaking change |
|
Closing as cant be merged automatically. Feel free to comment on this ticket to reopen it. @gitaarik Could you rebase onto master? |
|
I rebased my fork and fixed some tests that were using undefined model fields. However, there's one test still failing and I'm a bit confused about what to do with it: What is exactly being tested here? Should |
|
Its testing to make sure that setting a field doesnt overwrite the property. I think throwing the error is fine and we can now remove that test. The pr looks a little funky now on the changes so may need rebasing as some other changes are present - eg progressive JPEG which is also in master - so not sure why the change is listed in your pr. Also, can you add a regression test ensuring the exception is thrown |
|
It should be good now. I get one error when running the tests though, but I think that might has to do with my system because I also get it when I run the tests in the original repo: |
|
@thedrow I don't understand why Travis finds more errors than I do, I only get the one that I posted above, but I also get that one when I run the test on master of the original repo. |
|
@thedrow Ok, I never worked with Travis, but I guess it is because of a different environment, will look into it. |
|
Ok, now it seems the tests that are failing are not because of my changes, is that correct? |
|
@gitaarik sync the branch with master please. |
Now that fields need to be defined explicitly, it's not possible to have another property with the same name on a model. MongoEngine#457 (comment)
|
Ok now this is failing: I'm a bit puzzled about this one. I don't know about this Or make a |
|
Append 'text_score' in https://github.com/MongoEngine/mongoengine/pull/457/files#diff-e3e316e6686a3db66d2e679634f57f7fR65. Solve problem =D |
|
@wpjunior Ok, but what do you think of my other suggestions? And what if you have a document with a field |
|
I have an idea: Document.objects.start_search('blah lbh', text_score_field="text_blah") if field already defined raises an exception: FieldAlreadyExist |
|
What do you think of a |
|
@gitaarik see my Mockup: class MyDoc(Document)
text_score = FloatField()
meta = {'text_score_field': 'my_text_score_field'} |
|
@wpjunior No, what I mean is the following: I assume That's why I propose to use the I would propose to also use this |
|
Other simple alternative is creating a method In django not accept |
|
That solution would probably work, but I'm not sure about the elegance of it. To me, But I could be wrong. @rozza Maybe you can say something about what would be the best thing to do here. |
If an undefined field is supplied to a document instance, a `FieldDoesNotExist` Exception will be raised.
Now that fields need to be defined explicitly, it's not possible to have another property with the same name on a model. MongoEngine#457 (comment)
So it will be available when you do:
from mongoengine import *
When trying to set an undefined field.
Because otherwise we'll get a FieldDoesNotExist error on the field _created.
|
Ok, it's rebased. The issue with |
Now that fields need to be defined explicitly, it's not possible to have another property with the same name on a model. #457 (comment)
|
I fixed up, removing text score field and creating a method instead. Very thanks @gitaarik =D |
|
It was merged, just not through the pull request. https://github.com/MongoEngine/mongoengine/commits?author=gitaarik |
If an undefined field is supplied to a document instance, a
FieldDoesNotExistException will be raised. This way, you will be notified when you provide a field that does not exist.ATM when you do this:
It will create a document instance for
MyDoc. However, ifundefined_fielddoes not exist, the valuetestwon't end up anywhere. You'll think the object is successfully created with the provided values, but actually it isn't.To remedy this situation, an exception will be raised. This way you'll be noticed about your mistake in development. If the document instance is created dynamically on bases of an API call data for example, then you can catch the exeption and notify the API user that they have provided an undefined field.