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

DataError on to_alias field name (254 > 40) #7

Closed
roman-karpovich opened this issue Feb 2, 2018 · 11 comments
Closed

DataError on to_alias field name (254 > 40) #7

roman-karpovich opened this issue Feb 2, 2018 · 11 comments

Comments

@roman-karpovich
Copy link

drfpasswordless can't be used with contrib.auth.User model, because AbstractBaseCallbackToken.to_alias field, which in theory should contain user email, is just 40 symbols length, while default value for user email max_length = 254.

  File "/root/code/EquiTrack/email_auth/utils.py", line 24, in get_token_auth_link
    token = create_callback_token_for_user(user, 'email')
  File "/root/code/env1/lib/python2.7/site-packages/drfpasswordless/utils.py", line 45, in create_callback_token_for_user
    to_alias=getattr(user, api_settings.PASSWORDLESS_USER_EMAIL_FIELD_NAME))
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create
    obj.save(force_insert=True, using=self.db)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/base.py", line 708, in save
    force_update=force_update, update_fields=update_fields)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/base.py", line 736, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/base.py", line 820, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/base.py", line 859, in _do_insert
    using=using, raw=raw)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/query.py", line 1039, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1060, in execute_sql
    cursor.execute(sql, params)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/root/code/env1/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
DataError: value too long for type character varying(40)

i guess, field should be expanded, or at least cropped before saving (if custom user model will be used with even longer values).

@aaronn
Copy link
Owner

aaronn commented Feb 27, 2019

Yeah, field should be expanded to 254 (which is the RFC standard). Feel free to submit a PR with migrations, or I'll get to it when I can.

@Alig1493
Copy link

Steps to recreate issue?

@roman-karpovich
Copy link
Author

sorry, absolutely forgot about the issue :) created PR with test, which should be failed with current model, but it isn't. i also checked that resulting to_alias value will be equal to email, which is longer than field defined in model self.assertEqual(callback_token.to_alias, email)
https://travis-ci.org/aaronn/django-rest-framework-passwordless/jobs/520698631
@aaronn @Alig1493 maybe somebody is able to help with?

@aaronn
Copy link
Owner

aaronn commented Apr 16, 2019

hm, interesting. i don't have much time to dig into this right now but i'll check in on it on a weekend when I have time if somebody else doesn't find out why that test is passing

@Alig1493
Copy link

sorry, absolutely forgot about the issue :) created PR with test, which should be failed with current model, but it isn't. i also checked that resulting to_alias value will be equal to email, which is longer than field defined in model self.assertEqual(callback_token.to_alias, email)
https://travis-ci.org/aaronn/django-rest-framework-passwordless/jobs/520698631
@aaronn @Alig1493 maybe somebody is able to help with?

I'd like to take a crack at it. Could I use your branch?

@roman-karpovich
Copy link
Author

roman-karpovich commented Apr 17, 2019 via email

@Alig1493
Copy link

@roman-karpovich I forked and created a branch for myself hope that's okay. You can take a look I referenced this issue. I made a small change in the model save because django doesn't invoke model level validation on either save or create. As a result I had to call full_clean overriding the save method.

@roman-karpovich
Copy link
Author

roman-karpovich commented Apr 17, 2019 via email

@roman-karpovich
Copy link
Author

ok. anyway, models should be changed. does easy way exists to create alter field migration without manage.py script?

@aaronn
Copy link
Owner

aaronn commented Jan 21, 2020

I think we need to migrate for sure– why is that test you folks added passing? Very weird.

@aaronn
Copy link
Owner

aaronn commented Jan 22, 2020

Release 1.4+ fixes this by adding max_length=254.

@aaronn aaronn closed this as completed Jan 22, 2020
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

3 participants