Skip to content

refactor 401 retrying into both auth methods #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gmishkin
Copy link

@gmishkin gmishkin commented Oct 28, 2024

See #1904 for details on why.

This change refactors 401 retrying into the common base class, and for token auth the retry is implemented by clearing the session cookie and retrying with the same PAT as recommended.

In a few cases, the code is kind of ugly because in order to implement the retry I need to have a reference to the session object, which is only available if the tokenauth is created through the normal client constructor. If the tokenauth is created directly then the session might not be available. I am not sure if this is a supported case, if it's not then I might be able to clean up the checks for session and the asserts.

@gmishkin gmishkin marked this pull request as ready for review October 29, 2024 14:27
@gmishkin gmishkin requested a review from a team as a code owner October 29, 2024 14:27
@gmishkin gmishkin requested a review from ssbarnea October 29, 2024 14:27
@gmishkin gmishkin changed the title refactor 401 retrying into both auth methods DEVPROD-5571: refactor 401 retrying into both auth methods Nov 5, 2024
@gmishkin gmishkin changed the title DEVPROD-5571: refactor 401 retrying into both auth methods refactor 401 retrying into both auth methods Nov 5, 2024
@gmishkin
Copy link
Author

gmishkin commented Nov 8, 2024

@ssbarnea not sure what to do about the check failures, can you advise?

@Re4zOon
Copy link

Re4zOon commented Nov 26, 2024

Hi @adehad!

Can you please review this PR?

Thank you!

@Re4zOon
Copy link

Re4zOon commented Jan 13, 2025

Hi,

This is now impacting multiple workflows on our side.
Can you please merge this?
Seems like a simple change (compared of my PRs :D ).

self._retry_counter_401 = 0
self._max_allowed_401_retries = 1 # 401 aren't recoverable with retries really

def init_session(self):
"""Auth mechanism specific code to re-initialize the Jira session."""
raise NotImplementedError()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise NotImplementedError()
raise NotImplementedError()

let's make this an abstract base class and define this as an abstract method. To allow us to pick up errors in static analysis rather than runtime.

session_api_url (str): The session api url to use.
auth (Tuple[str, str]): The username, password tuple.
"""
def __init__(self, session: ResilientSession | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the default of None here, and then remove as many if not all the plain asserts.

If there do end up being situations where the session is None when passing to the constructor of the subclasses then let us move to a subclass __init__ method override, and rather than asserts, either use warnings, or if it should really fail, let's use an Exception with suitable message.
I want to avoid asserts in the production codebase.

@adehad adehad linked an issue Apr 16, 2025 that may be closed by this pull request
4 tasks
@gmishkin
Copy link
Author

@adehad I agree with both of your requested changes but just wanted to give you a heads up that we have our internal Jira 10 upgrade planned for next month, and if you look at the linked issue, it appears that someone found an upstream issue that matches the symptoms I was seeing here, that's fixed in Jira 10.

So, I may not get back to this PR, and honestly, you would be forgiven for closing this PR outright, since it's just a workaround for a bug that's resolved in the latest supported major version of the non-cloud Jira software (I don't know what your support policy is for older versions of the Jira server).

@adehad
Copy link
Contributor

adehad commented Apr 16, 2025

Thanks @gmishkin for this update, I didn't catch that.

Sorry for the delay in getting this merged when it would have made the most impact to you.

I think there is still value in keeping it open and even merging, as I can imagine there are individuals affected that won't get the change to migrate as soon. Happy to leave that decision to you or any other budding contributors and happy to facilitate.
(Based on this it may also be helpful to bring attention to that information in the code to help someone understand why we might have gone down this route, maybe pointing to the upstream issue / this PR)

I've just come back to open source contributions after a long pause, but now that I have time available I should be able to accelerate merging if it is ready.

@gmishkin
Copy link
Author

gmishkin commented Apr 16, 2025

@adehad I don't know if this is a thing that exists on GitHub, but if you're able to you should "pin" this comment

Adding a comment to the code describing what it's working around makes sense too 👍

P.S. no worries about not getting it merged, we have an internal pypi instance I've been publishing this so that our internal apps can use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TokenAuth can stop working if session cookie becomes invalid
4 participants