-
Notifications
You must be signed in to change notification settings - Fork 295
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
Deprecating Phone Fields #262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review this in complete detail, but I wanted to leave a few suggestions.
class PhoneNumberFormFieldMixin(object): | ||
def __init__(self): | ||
super(PhoneNumberFormFieldMixin, self).__init__() | ||
warnings.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with Django, I'd rather if you used from __future__ import unicode_literals
rather than u prefixes (which are obsolete when dropping support for Python 2).
Django style is:
warnings.warn(
"PhoneNumber form fields are deprecated in favor of the "
"django-phonenumber-field library.",
RemovedInLocalflavor20Warning,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timgraham I agree this is a good way to go. I'll update the docs that asks for u prefixed strings.
https://django-localflavor.readthedocs.io/en/latest/#adding-flavors
@@ -40,3 +40,19 @@ support for an unsupported version of Django. | |||
**2014-12-10 - 1.1**: Django 1.5 - 1.7 | |||
|
|||
**2013-07-29 - 1.0**: Django 1.5 - 1.6 | |||
|
|||
|
|||
**Roadmap** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this in the ocs rather than the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benkonrath could you point me where Roadmap will fit better please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladimirnani You can put this info in the releases section since this roadmap is changing the release policy for localflavor.
https://github.com/django/django-localflavor/blob/master/docs/index.rst#releases
@@ -38,6 +38,8 @@ Other changes: | |||
(`gh-257 <https://github.com/django/django-localflavor/pull/257>`_). Users will need to generate migrations for any | |||
model fields they use with 'makemigrations'. | |||
|
|||
- Adapting django deprecation policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't mean much to me. If you included the roadmap in the docs, you could link to it.
Also, include details of the deprecation in the docs.
@@ -49,6 +49,12 @@ class AUPhoneNumberField(CharField): | |||
"""A model field that checks that the value is a valid Australian phone number (ten digits).""" | |||
|
|||
description = _("Australian Phone number") | |||
system_check_deprecated_details = { | |||
'msg': ( | |||
"PhoneNumberFields has been deprecated.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has been -> is
|
||
class DeprecatedFieldsTests(SimpleTestCase): | ||
def setUp(self): | ||
logging.captureWarnings(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what warnings are being captured?
@@ -16,6 +16,7 @@ | |||
'tests.test_us', | |||
'tests.test_pk', | |||
'tests.test_generic', | |||
'tests.test_deprecated' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include a trailing comma so if more items are added to this list, we don't have to modify this line again.
@timgraham thanks for feedback will fix it shortly |
@timgraham btw maybe you know why my test fails on Django 1.7 |
Sorry that i haven't had time to review this yet. Thanks for the first review Tim. @vladimirnani The base class should be at the far right and the mixins to the left. That might be the cause of the test failures. |
The test failure is because |
I'm fine with dropping support for Django 1.7. We only kept it around because it wasn't causing problems. I've reopened #218 for this and will merge it shortly. |
@vladimirnani Please rebase your branch to get the version without the Django 1.7 tests. |
90b5e61
to
7f5028b
Compare
@benkonrath Ok. Done. |
7f5028b
to
5132306
Compare
@vladimirnani Just trying to get up to speed on this PR. Why are you using the Python warnings system for the form field deprecations instead to the Django system check framework? I can see that there's built-in support for deprecating model fields with the system check framework so it makes sense to use it. Couldn't we also add similar support (in localflavor) for deprecating form fields with the system check framework? Is there something "wrong" with using the Django system check framework for the form field depredations? Or is this just about Django conventions for deprecations of non-model fields? @timgraham Perhaps you have an idea about this? |
Thinking out loud ... I suppose one of the benefits to using the warnings system is that we could use the deprecation easily in other parts of localflavor. I'm still curious to understand the reasoning on the setup in the PR. Thanks. |
From a quick look, this approach looks like what we would do with Django, always using |
Thanks TIm. Let's stick with the Django approach for this and use Python warnings. |
Yes I have checked how it is being done in Django. So for now I think we can stick with warnings for everything except model fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladimirnani I've made some comments for some improvements. Thanks again for working on this.
Roadmap | ||
------- | ||
|
||
django-localflavor releases follows `semver`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follows -> follow
|
||
django-localflavor releases follows `semver`_. | ||
Within one month of django release we would release a new verision. | ||
We might have an extra release if there is lots features in between django releases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is lots -> if there are enough
1.4 November 2016 | ||
1.x ... | ||
2.0 January 2018 | ||
=========== =============== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's worth specifying the corresponding Django release? We know that localflavor 2.0 will correspond with Django 2.0 and that localflavor 1.4 is the (late) version for Django 1.10. We're not trying to match Django versions but having the matching Django version does highlight our "within one month" release policy. Anyway, just an idea. Add it only if you agree and think it makes things more clear.
@override_settings(SILENCED_SYSTEM_CHECKS=[]) | ||
def test_PhoneNumberField_deprecated(self): | ||
class PhoneNumberModel(Model): | ||
phone_number = models.NLPhoneNumberField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test all deprecated model fields? I think you can add a field for all of the phone number model fields to the same model. Thanks.
@@ -127,3 +132,13 @@ def prepare_value(self, value): | |||
if value is not None: | |||
return value.upper() | |||
return value | |||
|
|||
|
|||
class PhoneNumberFormFieldMixin(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have the word "Deprecation" or "Deprecated" in the class name. I realize that it makes it a pretty long name, but it helps to immediately know what it does.
super(PhoneNumberFormFieldMixin, self).__init__() | ||
warnings.warn( | ||
"PhoneNumber form fields are deprecated in favor of the " | ||
"django-phonenumber-field library.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using self.__class__.__name__
instead of referring generically to "PhoneNumber form fields". I think it would help make things clearer.
@@ -48,6 +48,12 @@ class PKPhoneNumberField(CharField): | |||
"""A model field that checks that the value is a valid Pakistani phone number (nine to eleven digits).""" | |||
|
|||
description = _("Pakistani Phone number") | |||
system_check_deprecated_details = { | |||
'msg': ( | |||
"PhoneNumberFields are deprecated.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use specific field name in the msg
for all of the model fields? That will make things more clear for users seeing this message.
from localflavor.nl import models | ||
|
||
|
||
class DeprecatedFieldsTests(SimpleTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test the form field deprecations as well? There are examples in the Django tests for this.
One last question: |
Actually, Django 1.11 removes the "Deprecation warnings loud by default" behavior. |
I guess that makes it easier for our release but less friendly for users. There's also an inconsistency here: deprecations on model fields will be loud because they use system check, deprecations on form fields will be silent unless a user takes a manual step to enable them. This seems like a good argument to use system check for all deprecations in localflavor. I don't want to expand the scope of this issue so I think we should continue as with the Python warnings as implemented in this PR. We can think about changing this later - perhaps with some discussion about this on django-devel. |
Unlike models, all forms aren't necessarily imported when the system check frameworks runs which is why it's infeasible to use it for form checks. |
Ok, got it. That's why system checks isn't used for form field deprecation in Django. Thanks. |
@vladimirnani Do you think you'll have time to update the PR soon? I'd like to get the 1.4 release out soon and this issue should be included in 1.4. If you're too busy, I can take over the PR but I'd like to then get your input on my changes which means I'd like you to review my PR. Let me know what is best for you. Thanks. |
@benkonrath I will find time tomorrow to update it. |
@benkonrath just found that there is |
5132306
to
bf23578
Compare
bf23578
to
4f954ba
Compare
Thanks @vladimirnani! |
Added deprecation for phone number fields in favor of django-phonenumber-field