Comments (3)
Hey @mihalikv, thanks for writing in.
To clarify, this my_custom_attribute
that you're putting on the user in your middleware example is the user_doc
from your Sentry screenshot I assume? And you are randomly getting an AttributeError
when trying to access it?
From the SDK point of view our only interaction with request.user
as far as I can see is here, where we copy some attributes from it over to the Sentry event. We shouldn't be modifying the user. We are accessing it though, which might potentially be relevant because of the whole Django SimpleLazyObject
business.
Could you post the full Python stacktrace for the error from your app's logs?
Do you use any additional auth middleware or any middleware that does something user
related?
from sentry-python.
Hi @sentrivana ,
yes you are right my_custom_attribute
in example is user_doc
in real application.
Full stack trace is(I am not sure, how can I provide more details):
AttributeError: 'User' object has no attribute 'user_doc'
File "django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "project/search/views.py", line 501, in get_rich_data
result = self.get_rich_data_from_es()
File "project/search/views.py", line 227, in get_rich_data_from_es
search = Catalog.search(index=self.index_name).protect_query(Catalog.get_query_filter(self.request.user))
File "project/search/mappings/default.py", line 134, in get_query_filter
document_filter = tenant.get_permissions().PERMISSIONS[user_group][cls.__name__]['handler'](licence, user, child_groups=child_groups)
File "project/search/permissions/tenant.py", line 268, in get_my_products
country = "sk" if user.user_doc["state"] == "Slovensko" else "cz"
File "django/utils/functional.py", line 259, in inner
return func(self._wrapped, *args)
Middleware definition is following:
MIDDLEWARE = [
'django_tenants.middleware.main.TenantMainMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_middleware_global_request.middleware.GlobalRequestMiddleware',
'project.basket.middleware.BasketMiddleware',
'project.account.middleware.AccountMiddleware',
'project.account.middleware.SwitchLanguage',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'project.account.middleware.CustomRedirectMiddleware',
]
It's probablly not very helpful, but I can say that in our custom middlewares we are also just accesing user_doc attribute and it's not replaced.
Another notable think is that we are using DRF and DRF process normal request to own custom request and even user is something special code here.
It was our first point of interest while trying to fix it. We even try to monkeypatch it in this way:
OriginalRequest = rest_framework.request.Request
class CustomRequest(OriginalRequest):
@property
def user(self):
user = self._request.user
user.user_doc = self._request.user_doc
return user
@user.setter
def user(self, value):
OriginalRequest.user.fset(self, value)
if OriginalRequest.__name__ != "CustomRequest":
rest_framework.request.Request = CustomRequest
but result was the same.
Fact is that error occures even on normal views and WSGI request so it's probably not a problem of DRF.
from sentry-python.
Ok, thanks for the information @mihalikv, we will continue investigating
from sentry-python.
Related Issues (20)
- "Generic WSGI Request" naming HOT 7
- Make ClickHouse integration work with `django-clickhouse-backend`
- `sentry_sdk.init` breaks `import exceptiongroup` in virtualenv activated with `activate_this.py` HOT 2
- Django doesn't run if you remove a rq job on app.ready HOT 4
- Deprecate undocumented `propagate_traces` option
- Handled exceptions from OpenAI are still being captured and reported on Sentry HOT 2
- gRPC (AIO) missing None check for when RPC method not implemented HOT 2
- Temporarily disable without re-initializing the client? HOT 1
- last_event_id() crash: AttributeError: 'Scope' object has no attribute '_last_event_id'. HOT 1
- Transactions from rest_framework.routers seem to be missing
- UnicodeDecodeError with certain Redis keys HOT 1
- Fix Migration Guide regarding removal of last_event_id() HOT 1
- POTel context <-> scope management
- Set up POTel patching
- Crons Celery: automatically clean up tasks that are no longer in use HOT 4
- Fix `cache_prefixes` check for multiple keys.
- Instrument Django app with Sentry and OTel and check differences. HOT 6
- Make sure int keys are handled by redis integration HOT 2
- Crons: Celerybeat integration provides invalid Crontab schedule HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-python.