You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VersionField and SpecField shouldn't accept strings, only Version / Spec objects. #97
test_one (__main__.SemverTest) ... SemVersion object
ERROR
======================================================================
ERROR: test_one (__main__.SemverTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ONT/user/apps/version/tests/test.py", line 20, in test_one
print(obj1.version.major)
AttributeError: 'str' object has no attribute 'major'
----------------------------------------------------------------------
Ran 1 testin 0.022s
FAILED (errors=1)
output second run:
test_one (__main__.SemverTest) ... SemVersion object
0
1
1
()
('build',)
ok
----------------------------------------------------------------------
Ran 1 testin 0.015s
OK
looks like the the create part of get_or_create returns not an object but a string, the second time get_or_create is run the get part kicks in and returns a correct version object. This is inconsistent and should work. Tested it with python 3.6 and 2.7 both same results. Django 1.11.15
After taking a deeper look, it seems to be a standard behaviour from Django: if the developer provides a badly-typed-but-coercable value, it might be used properly by the database, but the value on the model won't be changed.
This is, unfortunately, not properly documented in Django.
changed the title [-]SemVersion.objects.get_or_create invalid behaviour[/-][+]VersionField and SpecField shouldn't accept strings, only `Version` / `Spec` objects.[/+]on Jul 7, 2020
After taking a deeper look, it seems to be a standard behaviour from Django: if the developer provides a badly-typed-but-coercable value, it might be used properly by the database, but the value on the model won't be changed.
This is, unfortunately, not properly documented in Django.
Activity
rbarrois commentedon Jul 7, 2020
Thanks for the report! That's indeed a bug, likely because Django's
get_or_createreturns the value as is.Add tests for Django's get_or_create.
rbarrois commentedon Jul 7, 2020
After taking a deeper look, it seems to be a standard behaviour from Django: if the developer provides a badly-typed-but-coercable value, it might be used properly by the database, but the value on the model won't be changed.
This is, unfortunately, not properly documented in Django.
Here are a couple of links on that topic:
DecimalField: https://code.djangoproject.com/ticket/27825;Basically, a
VersionFieldshouldn't accept a string, only aVersionobject; that's the bug ;)[-]SemVersion.objects.get_or_create invalid behaviour[/-][+]VersionField and SpecField shouldn't accept strings, only `Version` / `Spec` objects.[/+]ejosan commentedon Jul 8, 2020
;-)