AttributeError: 'SimpleLazyObject' object has no attribute 'match'
I have a Django 3.2 application running with gunicorn 23 on Python 3.9. The app is in docker container with all other dependencies installed in virtualenv.
I am getting this error:
Traceback (most recent call last):
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/middleware.py", line 175, in __call__
return f(*args, **kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/deprecation.py", line 116, in __call__
response = self.process_request(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/middleware/locale.py", line 21, in process_request
language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/translation/__init__.py", line 291, in get_language_from_request
return _trans.get_language_from_request(request, check_path)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/translation/trans_real.py", line 531, in get_language_from_request
lang_code = get_language_from_path(request.path_info)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/translation/trans_real.py", line 510, in get_language_from_path
regex_match = language_code_prefix_re.match(path)
AttributeError: 'SimpleLazyObject' object has no attribute 'match'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/middleware.py", line 175, in __call__
return f(*args, **kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/deprecation.py", line 117, in __call__
response = response or self.get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 153, in handle_uncaught_exception
return callback(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/decorators.py", line 126, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/middleware/csrf.py", line 269, in process_view
good_referer = request.get_host()
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 142, in get_host
domain, port = split_domain_port(host)
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 665, in split_domain_port
if not host_validation_re.match(host):
AttributeError: 'SimpleLazyObject' object has no attribute 'match'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/middleware.py", line 175, in __call__
return f(*args, **kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/deprecation.py", line 117, in __call__
response = response or self.get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 153, in handle_uncaught_exception
return callback(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/decorators.py", line 126, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/middleware/csrf.py", line 269, in process_view
good_referer = request.get_host()
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 142, in get_host
domain, port = split_domain_port(host)
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 665, in split_domain_port
if not host_validation_re.match(host):
AttributeError: 'SimpleLazyObject' object has no attribute 'match'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/middleware.py", line 175, in __call__
return f(*args, **kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/deprecation.py", line 117, in __call__
response = response or self.get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 153, in handle_uncaught_exception
return callback(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/decorators.py", line 126, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/middleware/csrf.py", line 269, in process_view
good_referer = request.get_host()
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 142, in get_host
domain, port = split_domain_port(host)
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 665, in split_domain_port
if not host_validation_re.match(host):
AttributeError: 'SimpleLazyObject' object has no attribute 'match'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/web/.venv/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 134, in handle
self.handle_request(listener, req, client, addr)
File "/app/web/.venv/lib/python3.9/site-packages/gunicorn/workers/sync.py", line 177, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/__init__.py", line 128, in sentry_patched_wsgi_handler
return SentryWsgiMiddleware(bound_old_app, use_x_forwarded_for)(
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/wsgi.py", line 143, in __call__
reraise(*_capture_exception(hub))
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/_compat.py", line 54, in reraise
raise value
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/wsgi.py", line 136, in __call__
rv = self.app(
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/app/web/.venv/lib/python3.9/site-packages/sentry_sdk/integrations/django/__init__.py", line 407, in sentry_patched_get_response
rv = old_get_response(self, request)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 130, in get_response
response = self._middleware_chain(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 114, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/app/web/.venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 153, in handle_uncaught_exception
return callback(request)
File "/app/web/.venv/lib/python3.9/site-packages/django/utils/decorators.py", line 126, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/app/web/.venv/lib/python3.9/site-packages/django/middleware/csrf.py", line 269, in process_view
good_referer = request.get_host()
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 142, in get_host
domain, port = split_domain_port(host)
File "/app/web/.venv/lib/python3.9/site-packages/django/http/request.py", line 665, in split_domain_port
if not host_validation_re.match(host):
AttributeError: 'SimpleLazyObject' object has no attribute 'match'
The error is not coming from my code and the weird part is that it is occurring in seemingly random time windows (eg. it can start at 4 am and return to normal at 9 am (without restarting the app)). When the app is in "error" state, most of the requests fail with this error (~95%) but some still succeeds.
I am using upstream Python 3.9 docker image. Project is managed by uv
.
The error only happens in production environment (maybe because of number of requests but tbh I don't know). That means I was not able to reproduce it myself locally.
I've looked up how SimpleLazyObject
is implemented to better understand what is happening. I have also try to google this error but I have found nothing.
I don't know what can be causing this weird behaviour. It is possible that the CPU is broken in some way?