-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Address save via admin saves the primary key into raw column, and additionally creates a bare new object #177
Comments
Hi @jheld, thanks for the report! Would you be able to give me the steps required to reproduce the issue you're experiencing? |
Ok, I think I have isolated the scenario further. In my case, I am using In the admin, if I simply save and continue editing, but don't actually change anything (the address must already have a foreign key value in this situation), then the issue will arise. Every time we submit, even with no change at all, there is a new address instance created, and the foreign key's value will simply increase, while it's "human readable" (e.g. My current iteration of the fix is effectively this (note I am wrapping the behavior of the function more explicitly): def address_to_python(value):
if isinstance(value, int) or (isinstance(value, str) and value.isnumeric()):
obj = Address.objects.filter(pk=value).first() or value
return obj
else:
return address.models.to_python(value) When we use the raw_id_fields, django will send down the I did fork the project and write up a "successful" failure case (e.g. class AddressDescriptor(ForwardManyToOneDescriptor):
def __set__(self, inst, value):
super(AddressDescriptor, self).__set__(inst, to_python(value)) But given that I was able to isolate the issue more explicitly, I don't think my grass-roots test is all the valuable anymore (e.g. we'd want a test with the fix in place, not the problem itself being tested). |
Thanks for the response! I think I understand the situation; using |
Looks like the general culprit is from https://github.com/furious-luke/django-address/blame/develop/address/models.py#L138 which is based on the "ID" coming in as a
str
, as opposed to anint
.I have a fix temporarily in-place via subclassing in my project.
It looks similar to:
The text was updated successfully, but these errors were encountered: