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

Use of Django Internal Property #254

Closed
kahnvex opened this issue Apr 21, 2014 · 3 comments
Closed

Use of Django Internal Property #254

kahnvex opened this issue Apr 21, 2014 · 3 comments

Comments

@kahnvex
Copy link

kahnvex commented Apr 21, 2014

Python Social Auth's Django App directly references a property that is marked for internal use only.

field = UserSocialAuth.user_model()._meta.get_field(username_field)

The use of _meta here is problematic for applications that are service oriented by nature. If your user store is a service consumed by a client that houses python social auth (like a legacy user store) you should not have to implement all the "internal" stuff (like _meta) that a Django model has. By adding a simple check this could probably be avoided.

@kahnvex
Copy link
Author

kahnvex commented Apr 21, 2014

Suggest:

@classmethod
def username_max_length(cls):
    username_field = cls.username_field()
    user_model = UserSocialAuth.user_model()
    field = getattr(user_model, username_field)
    if hasattr(field, 'max_length'):
        return field.max_length

    return settings.USERNAME_FIELD_MAX_LENGTH

@omab
Copy link
Owner

omab commented Apr 23, 2014

Could you show me an example where _meta doesn't work? _meta is populated by Django ORM when the model class is defined, you can't do getattr(User, 'username'), that will drop an attribute error since the model class doesn't have that attribute.

@omab
Copy link
Owner

omab commented May 7, 2014

Closing, reopen if needed.

@omab omab closed this as completed May 7, 2014
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

No branches or pull requests

2 participants