Skip to content
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

Merged
merged 1 commit into from
Dec 18, 2016
Merged

Conversation

vladimirnani
Copy link
Contributor

Added deprecation for phone number fields in favor of django-phonenumber-field

Copy link
Member

@timgraham timgraham left a 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(
Copy link
Member

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,
)

Copy link
Member

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**
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@benkonrath benkonrath Nov 11, 2016

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
Copy link
Member

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.",
Copy link
Member

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)
Copy link
Member

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'
Copy link
Member

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.

@vladimirnani
Copy link
Contributor Author

@timgraham thanks for feedback will fix it shortly

@vladimirnani
Copy link
Contributor Author

@timgraham btw maybe you know why my test fails on Django 1.7

@benkonrath
Copy link
Member

benkonrath commented Nov 10, 2016

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.

@timgraham
Copy link
Member

The test failure is because system_check_deprecated_details is new in Django 1.8. If it were up to me, i would drop support for Django 1.7 at this point as it's unsupported by the Django team.

@benkonrath
Copy link
Member

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.

@benkonrath
Copy link
Member

@vladimirnani Please rebase your branch to get the version without the Django 1.7 tests.

@vladimirnani
Copy link
Contributor Author

@benkonrath Ok. Done.

@benkonrath
Copy link
Member

@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?

@benkonrath
Copy link
Member

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.

@timgraham
Copy link
Member

From a quick look, this approach looks like what we would do with Django, always using warnings for deprecations, except for deprecation of model fields.

@benkonrath
Copy link
Member

Thanks TIm. Let's stick with the Django approach for this and use Python warnings.

@vladimirnani
Copy link
Contributor Author

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.

Copy link
Member

@benkonrath benkonrath left a 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`_.
Copy link
Member

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.
Copy link
Member

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
=========== ===============
Copy link
Member

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()
Copy link
Member

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):
Copy link
Member

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.",
Copy link
Member

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.",
Copy link
Member

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):
Copy link
Member

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.

@benkonrath
Copy link
Member

One last question: DeprecationWarning and PendingDeprecationWarning are ignored by default in Python. I see the DeprecationWarnings on the console from Django when code uses something that will be removed. How can localflavor also have the DeprecationWarnings printed on the console? I tried this PR in an existing Django 1.10 / Python 3.4 project with the PendingDeprecationWarning changed to DeprecationWarning and didn't see the warnings in the console.

@timgraham
Copy link
Member

Actually, Django 1.11 removes the "Deprecation warnings loud by default" behavior.

@benkonrath
Copy link
Member

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.

@timgraham
Copy link
Member

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.

@benkonrath
Copy link
Member

Ok, got it. That's why system checks isn't used for form field deprecation in Django. Thanks.

@benkonrath
Copy link
Member

@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.

@vladimirnani
Copy link
Contributor Author

@benkonrath I will find time tomorrow to update it.

@vladimirnani
Copy link
Contributor Author

@benkonrath just found that there is CNCellNumberField alongside with CNPhoneNumberField That one also should be deprecated.

@benkonrath benkonrath merged commit c078000 into django:master Dec 18, 2016
@benkonrath
Copy link
Member

Thanks @vladimirnani!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants