Skip to content
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

Parse 'session_required_policies' to a list #678

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Feb 6, 2023

Rather than keeping the string which an API may pass back, convert it to the list of IDs by comma-splitting the value. If the value is not a string, the comma split won't be possible, so this is handled by treating anything other than a string as invalid (and setting the attribute to None).

This also makes this property a little bit safer than many of our other computed properties, which are cast to the "right" types by the SDK but aren't validated.

The change is technically backwards incompatible, but surrounds the use of a feature which is not in production use yet, and we have therefore agreed upon pragmatic treatment of this case as not requiring a major version bump.

The test changes include updates to check the parsed value(s), but also a general update to the ErrorInfo tests to split a monolithic test into more individual cases.

Copy link
Contributor

@aaschaer aaschaer left a comment

Choose a reason for hiding this comment

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

Looks good to me, part of me wants to somehow warn the user that there was session_required_policies, but it wasn't a string so something is wrong. But I can't think of a clean way to do that, and hopefully that issue would manifest in other ways like the session message not making sense.

I left a small style comment/question, but feel free to leave as is

# get str|None and parse as appropriate
session_required_policies = data.get("session_required_policies")
if isinstance(session_required_policies, str):
self.session_required_policies: t.Optional[
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but it feels odd to only have the type information in the if branch and not the else branch for some reason. Does a pattern like this seem better or is it just me?

self.foo: t.Optional[t.fooType] = None
if condition_for_foo_existing:
    self.foo = bar

Copy link
Member Author

Choose a reason for hiding this comment

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

It's stopped looking odd to me to do the typing assignment like this, but that doesn't mean it isn't odd. It just means that I've done it too many times. 😉

I think I'll make a modification here to be similar to your suggestion, but also add a warning log for the present-but-not-string case. (I don't think we can do more than that.)

Rather than keeping the string which an API may pass back, convert it
to the list of IDs by comma-splitting the value. If the value is not a
string, the comma split won't be possible, so this is handled by
treating anything other than a string as invalid (and setting the
attribute to None).

This also makes this property a little bit safer than many of our
other computed properties, which are cast to the "right" types by the
SDK but aren't validated.

The change is technically backwards incompatible, but surrounds the
use of a feature which is not in production use yet, and we have
therefore agreed upon pragmatic treatment of this case as not
requiring a major version bump.

The test changes include updates to check the parsed value(s), but
also a general update to the ErrorInfo tests to split a monolithic
test into more individual cases.
If the type is not `str|None`, log a warning about the unexpected
type.
@sirosen sirosen force-pushed the parse-required-policies branch from 7cf5ab9 to e2433f4 Compare February 7, 2023 00:07
src/globus_sdk/exc/err_info.py Outdated Show resolved Hide resolved
src/globus_sdk/exc/err_info.py Outdated Show resolved Hide resolved
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
@sirosen sirosen merged commit 0b8b484 into globus:main Feb 7, 2023
@sirosen sirosen deleted the parse-required-policies branch February 7, 2023 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants