djangorestframework-simplejwt icon indicating copy to clipboard operation
djangorestframework-simplejwt copied to clipboard

fix: Avoid DoesNotExist exception in TokenRefreshSerializer

Open yuekui opened this issue 10 months ago • 5 comments

https://github.com/jazzband/djangorestframework-simplejwt/issues/860 For deleted users, they should be treated the same as when no active user is found. This DoesNotExist exception was introduced in the previous version.

yuekui avatar Feb 06 '25 20:02 yuekui

qq @yuekui @mjbogusz : are you facing 500 error exceptions with this? In other words, are you having to manually catch this edge case? I noticed that the DRF exception does not inherit from the user not found exception, making this a breaking change

Andrew-Chen-Wang avatar Mar 15 '25 03:03 Andrew-Chen-Wang

I didn't get as far as getting 500s, as I was upgrading from 5.0 and our unit tests failed on previously unexpected UserNotFound.

AuthenticationFailed is already handled by DRF's APIView:handle_exception() and it's consistent with neighboring behavior for a not active account, so I've added handling this edge case by raising the same type of error and our tests passed again without any additional error handling.

mjbogusz avatar Mar 17 '25 14:03 mjbogusz

qq @yuekui @mjbogusz : are you facing 500 error exceptions with this? In other words, are you having to manually catch this edge case? I noticed that the DRF exception does not inherit from the user not found exception, making this a breaking change

Yes, it's a 500 error and a breaking change for me. That's why I opened the issue and submitted the patch right after v5.4.0 was released.

yuekui avatar Mar 17 '25 15:03 yuekui

Got it, it sounds like a patch release is necessary rather than a minor/major version upgrade.

Andrew-Chen-Wang avatar Mar 17 '25 18:03 Andrew-Chen-Wang

I'd say this sounds like a minor-release-level change, as it shouldn't require immediate code adjustments whether or not someone has implemented a workaround like my example in #860; the behavior will change slightly though.

The exception thrown is the same as previously and is handled by DRF already so I wouldn't say it's a breaking change either.

But of course the final decision is up to the maintainers - I'm just hoping the fix will land soon ;)

mjbogusz avatar Mar 25 '25 10:03 mjbogusz