-
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
Setter does not behave as it should. #1059
Comments
Hi, From my point of view, the trouble is when
I guess we should overload Document setter to call |
I've pushed a first quick fix to use Plenty of tests are broken with this, but I'm wondering if this doesn't hide a bigger refactoring need, see for example: 511 def test_boolean_validation(self):
512 """Ensure that invalid values cannot be assigned to boolean fields.
513 """
514 class Person(Document):
515 admin = BooleanField()
516
517 person = Person()
518 person.admin = True
519 person.validate()
520
521 person.admin = 2
522 -> self.assertRaises(ValidationError, person.validate) # My fix makes the test break here
523 person.admin = 'Yes'
524 self.assertRaises(ValidationError, person.validate)
(Pdb) person.admin # admin field has been converted by my `to_python` from an `int` to a `boolean`...
True
(Pdb) Person(admin=2).admin # ...but it's already the behaviour when giving a field at creation time !
True |
Could you add this to your test case? Person(admin=[]).admin
# if this returns False, then the problem is python's duck-typing If the problem is indeed Python's duck-typing, then a good feature would be to implement a more restrictive 'type casting' on the |
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: