X Tutup
The Wayback Machine - https://web.archive.org/web/20201215212401/https://github.com/MongoEngine/mongoengine/pull/2299
Skip to content
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

Fix a bug when using None values in a list of floats #2299

Open
wants to merge 3 commits into
base: master
from

Conversation

@Adam-Edry
Copy link

@Adam-Edry Adam-Edry commented Apr 5, 2020

Fixing a bug reported in issue #2290.

When trying to use None values in a List of Floats there would be an exception thrown from either to_python or validate methods.

Added two failing tests that cover each of those functions and then fixed them.

@Adam-Edry
Copy link
Author

@Adam-Edry Adam-Edry commented Apr 5, 2020

I was able to run black and run the tests locally however initially some of the tests were failing. No other old tests started failing after my changes so hopefully everything is alright.

I'm not sure if this warrants a mention in docs/changelog.rst

Let me know if I put the tests in the wrong place.

@Adam-Edry
Copy link
Author

@Adam-Edry Adam-Edry commented Apr 5, 2020

Seems like some of the travis ci tests failed. Looks like there is some issue with configparser. When installing locally I had to pip install configparser to get the tests to run.

Edit: configparser released a new version 5.0.0 recently. Looks like you need to require configparser< 5 to use with older python versions
jaraco/configparser@5388e94

@bagerard
Copy link
Collaborator

@bagerard bagerard commented Apr 9, 2020

I've fixed the problem with configparser, could you pull master in your branch?

@Adam-Edry Adam-Edry force-pushed the Adam-Edry:add-float-field-none-value branch from 1c62a46 to 83c1446 Apr 9, 2020
@Adam-Edry
Copy link
Author

@Adam-Edry Adam-Edry commented Apr 9, 2020

Done. Thank you

@bagerard
Copy link
Collaborator

@bagerard bagerard commented Apr 11, 2020

Just had a look at this. The PR looks great but I'm afraid that the actual "problem" is in the ListField, here you are fixing it for the FloatField but the problem remains for other fields (StringField, etc) so the behavior is not consistent across the fields. I'm trying to understand what could be the impact if we change that in the ListField itself

@Adam-Edry
Copy link
Author

@Adam-Edry Adam-Edry commented Apr 12, 2020

I see. I haven't taken a look at ListField but I agree that inconsistent behavior is not what we want. Hopefully I will have time to take a closer look at ListField tomorrow. Although, given my unfamiliarity with this code base I may not be the best person to consider widespread impacts and whether or not that would be a breaking change.

@Adam-Edry
Copy link
Author

@Adam-Edry Adam-Edry commented Apr 13, 2020

It seems to me that ListField defers the validation and to_python methods to whatever class the list element has. This happens in the ancestors of ListField - ComplexBaseField in to_python method and BaseField in _validate.

I see two ways to approach this.
One is to start fixing the classes that aren't collections (int float etc) if they have an issue.
Two is to fix the collection classes such as ListField and DictField etc.

I don't know which approach is better. I would lean towards the first because that is where there is currently an inconsistency. For example StringField's to_python function does work with None however validate does not. Same case with other fields. It was only a coincidence that I stumbled upon this issue with FloatField and its to_python method.

I would be glad to hear your thoughts on this @bagerard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
X Tutup