SV-246: Add access to request in handle_errors#73
Conversation
esteid/mixins.py
Outdated
| def handle_errors(self, e: Exception, stage: SessionStageType = "start", request: HttpRequest = None): | ||
| self.on_failure(e, stage, request) |
There was a problem hiding this comment.
Perhaps we can get away with just passing request to handle_errors and the developer would be responsible to add side effects and calling super on that overwritten method
|
CI is broken due to oscrypto not working with newer ubuntu versions. Last release that it worked with is Bullseye |
esteid/mixins.py
Outdated
| pass | ||
|
|
||
| def handle_errors(self, e: Exception, stage="start"): | ||
| def on_failure(self, e: Exception, stage: SessionStageType, request: HttpRequest): |
There was a problem hiding this comment.
Here we change the signature of handle_errors, which is not backwards compatible. I am not 100% sure how bad it is (I don't think it is used outside a certain project you need the change for), but it is not great (especially not great since we don't have any comprehensive change-log that I would be aware of to empathize the fact there is a breaking change).
To work around this, we could create a context variable (per view instance) and then set that in dispatch to hold request. Then we could read it from context variable, if necessary, in on_failure / handle_errors.
Why context variable? There is a concern in another MR that needs checking, if setting an instance property on view would break in django async. If the concern is correct (we didn't check it, but it probably is) then context variable is better; if the concern isn't correct then it can just be an instance property like self._request.
There was a problem hiding this comment.
handle_errors is backward compatibly since the request is optional param there and it is passed in post and patch calls 🤔 also it is the last arg so optional..
There was a problem hiding this comment.
Argument is optional, but if the method is overridden by a subclass in the project using the library the signature should match
There was a problem hiding this comment.
you are right here, tried contextvar approach now
esteid/mixins.py
Outdated
| """ | ||
| pass | ||
|
|
||
| def handle_errors(self, e: Exception, stage: SessionStageType = "start", request: HttpRequest = None): |
There was a problem hiding this comment.
Why do we need to have a separate on_failure if we can just override handle_errors and do
def handle_errors(...):
do_whatever_on_failure_needs_to_do()
return super().handle_errors(...)
There was a problem hiding this comment.
yes I tihnk it would make sense to remove separate on_failure and do it with super
|
Regards the CI issue, I suppose we'll have to move over to |
For audit side-effects on errors added context var and public getter for the current request