Suor / django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
BSD 3-Clause "New" or "Revised" License
2.12k stars 227 forks source link

dj-rest-auth no longer able to save user on register after install #436

Closed billpull closed 2 years ago

billpull commented 2 years ago

After adding django-cacheops user registration broke on in application. Attempting to disable all cacheops on models related to auth and rest_framework but issue still persisted.

I am not really sure how the two packages interop yet, just getting started with cacheops, so any tips for debugging would be helpful.

Exception

ERROR Register User Failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: ''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/code/users/serializers.py", line 246, in save
    adapter.save_user(request, user, self)
  File "/usr/local/lib/python3.8/site-packages/allauth/account/adapter.py", line 243, in save_user
    user.save()
  File "/code/users/models.py", line 144, in save
    return super().save(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 67, in save
    super().save(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 787, in save_base
    post_save.send(
  File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 180, in send
    return [
  File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/usr/local/lib/python3.8/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/usr/local/lib/python3.8/site-packages/cacheops/invalidation.py", line 21, in skip_on_no_invalidation
    return call()
  File "/usr/local/lib/python3.8/site-packages/funcy/decorators.py", line 66, in __call__
    return self._func(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/cacheops/query.py", line 447, in _post_save
    invalidate_obj(instance, using=using)
  File "/usr/local/lib/python3.8/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/usr/local/lib/python3.8/site-packages/cacheops/invalidation.py", line 21, in skip_on_no_invalidation
    return call()
  File "/usr/local/lib/python3.8/site-packages/funcy/decorators.py", line 66, in __call__
    return self._func(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/cacheops/invalidation.py", line 45, in invalidate_obj
    invalidate_dict(model, get_obj_dict(model, obj), using=using)
  File "/usr/local/lib/python3.8/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/usr/local/lib/python3.8/site-packages/funcy/flow.py", line 224, in post_processing
    return func(call())
  File "/usr/local/lib/python3.8/site-packages/cacheops/invalidation.py", line 117, in get_obj_dict
    yield field.attname, field.get_prep_value(value)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 977, in get_prep_value
    return self.target_field.get_prep_value(value)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(
ValueError: Field 'id' expected a number but got ''.
ERROR Internal Server Error: /api/v1/dj-rest-auth/registration/
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 581, in get_or_create
    return self.get(**kwargs), False
  File "/usr/local/lib/python3.8/site-packages/cacheops/query.py", line 353, in get
    return qs._no_monkey.get(qs, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
rest_framework.authtoken.models.Token.DoesNotExist: Token matching query does not exist.

Pipfile

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "==3.2.15"
psycopg2-binary = "==2.8.4"
django-crispy-forms = "==1.8.1"
django-allauth = "==0.41.0"
pillow = "~=9.1.1"
whitenoise = "==5.0.1"
gunicorn = "==20.0.4"
dj-database-url = "==0.5.0"
python-slugify = "==4.0.0"
django-phonenumber-field = {extras = ["phonenumbers"],version = "==6.1.0"}
django-ipware = "==4.0.2"
geoip2 = "==4.6.0"
numpy = "==1.22.3"
django-guardian = "==2.2.0"
twilio = "==6.62.1"
django-bootstrap-modal-forms = "==2.2.0"
django-formtools = "==2.3"
python-dateutil = "==2.8.2"
sendgrid = "==6.9.7"
django-sendgrid-v5 = "==1.2.0"
phonenumbers = "==8.10.16"
xlrd = "==2.0.1"
simplejson = "==3.17.6"
ohmysportsfeedspy = "==2.1.1"
django-paypal = "==2.0"
pandas = "==1.4.2"
django-storages = {extras = ["boto3"], version = "==1.12.3"}
stripe = "==3.0.0"
django-environ = "==0.8.1"
django-cors-headers = "==3.5.0"
djangorestframework = "==3.13.1"
djangorestframework-camel-case = "==1.3.0"
uvicorn = {extras = ["standard"], version = "==0.17.6"}
django-debug-toolbar = "==3.2.4"
babel = "==2.10.1"
celery = "==5.0.0"
redis = "==4.3.4"
geopy = "==2.2.0"
django-celery-beat = "==2.2.1"
django-intl-tel-input = "==0.3.1"
bs4 = "==0.0.1"
django-qr-code = "==3.0.0"
dj-rest-auth = "==2.2.4"
channels = "==3.0.4"
channels-redis = "==3.3.0"
twisted = "==20.3.0"
tweepy = "~=4.7.0"
stream-chat = "==3.1.0"
typing_extensions = "==4.2.0"
django-redis = "==5.0.0"
hubspot-api-client = "~= 3.8"
django-auditlog = "==1.0a1"
drf-api-tracking = "==1.8.0"
websockets = "==10.1"
django-datadog-logger = "==0.5.0"
drf-yasg = "*"
ddtrace = "*"
django-cacheops = "*"

[requires]
python_version = "3.8"

Settings

CACHEOPS = {
    # Disable Op for User/Auth
    'auth.*': None,
    'rest_framework.authtoken.models.token': None,

    # Default all model ops caching to 1 minute
    '*.*': {'timeout': 60},
}
billpull commented 2 years ago

Ignoring the users.* fixed the issue.