-
Notifications
You must be signed in to change notification settings - Fork 315
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
Extension information is lost during serialization #581
Comments
This also causes extension info to be deleted after running clean()! |
Hi, thanks for raising the issue. I believe the serialization ( When either setting is set to The doc on I don’t see tests verifying phone number extension handling either, it might be a great addition. For the record, I’ve had success with the string I’ll see about addressing these issues in the upcoming weeks. Please feel free to offer pull requests, that will speed up the resolution. :) |
I found the documentation mostly satisfactory here, I have both variables set to the following
Now in a Django shell I have a User model with a PhoneNumberField.
Let me know if you cannot reproduce that, it's possible I'm doing something wrong still. I can tray and create a more contained reproduction as well. Similarly, when I run
Notice that this is not in international format, despite the settings, and that the phone number does not contain the extension. Is it possible I'm not doing the setting correctly? |
You need to define >>> from phone.models import Person
>>> user = Person.objects.get()
>>> user.cell
PhoneNumber(country_code=33, national_number=555001489, extension='66', italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=1, preferred_domestic_carrier_code=None)
>>> user.full_clean()
>>> user.cell
PhoneNumber(country_code=33, national_number=555001489, extension='66', italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=1, preferred_domestic_carrier_code=None) Let me know if that fixes the issue. To confirm the settings values, you can rely on django |
Ah, I see! I didn't realize this was a different variable! Thanks for your patience. This did indeed fix the problem. It looks like your PR should cover this. My testing seems to indicate that there is no issue, but I wanted to confirm; is there any risk in changing these variables with data already stored in the database? Initially I expected there to be a migration or something, but there wasn't. It seems that the field is parsed regardless of the format. It might be worth making that explicit in the docs as well. Also feel free to close this issue, my problem is solved! |
Thanks for your feedback, glad the issue is solved. 😁
I don’t think so, as you’ve noticed, the field is parsed regardless of the format. The cases where you would be in trouble:
That’s correct. I’m tempted to leave it undocumented, as I don’t want to commit to this behavior. It’s the best way to obtain a PhoneNumber for now, but maybe there will be optimized helpers in the future that do not validate the phone number, or a good reason to change that behavior. I would rather avoid giving some guarantee for implementation details if that can be avoided. |
It makes sense to not want to commit to particular behavior. Unfortunately the current behavior is already being relied upon. Anyone who changes these variable with a database running is dependent upon the current behavior of flexible parsing. Changes to the parsing behavior will probably need to be documented (or else result in some nasty surprises). Regardless, this information:
was very useful to me, and would probably be useful to other users who find that they need to change the db format. In my case it was to support extensions. I saw you were considering changing the default format to support extensions which would avoid cases like mine. I think that's a good idea! |
Makes sense, I added a warning to the |
Firstly, thanks for an awesome library!
It looks to me like the extension information is lost when using Django's built in serialization. We only use this for loading our test database, but it was surprising when the extension's didn't survive reloading the data.
After a little bit of investigation, I think fixing this should be pretty straight forwards, we would just need to implement
value_to_string()
for the field with one of the lossless serialization formats and then make sure the theto_python()
function can handle it properly.https://docs.djangoproject.com/en/4.2/howto/custom-model-fields/#converting-field-data-for-serialization
If the contribution is welcome, I might be interested in adding this fix. Thanks again!
The text was updated successfully, but these errors were encountered: