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

fix access to core_version in get_flow_run_command() #3177

Merged
merged 3 commits into from Aug 17, 2020
Merged

fix access to core_version in get_flow_run_command() #3177

merged 3 commits into from Aug 17, 2020

Conversation

jameslamb
Copy link

Summary

In #3113 , agents were changed to choose a different flow run command based on the current version of Prefect Core managing the flow. That PR added a default for core_version for the cases where {"core_version": null} exists on the response. However, if core_version is not present on the response at all, you get this hard-to-understand error:

item = 'core_version'

    def __getattr__(self, item):
        try:
            try:
                value = self.__getitem__(item, _ignore_default=True)
            except KeyError:
                value = object.__getattribute__(self, item)
        except AttributeError as err:
            if item == '__getstate__':
                raise BoxKeyError(item) from None
            if item == '_box_config':
                raise BoxError('_box_config key must exist') from None
            if self._box_config['conversion_box']:
                safe_key = self._safe_attr(item)
                if safe_key in self._box_config['__safe_keys']:
                    return self.__getitem__(self._box_config['__safe_keys'][safe_key])
            if self._box_config['default_box']:
                return self.__get_default(item)
>           raise BoxKeyError(str(err)) from None
E           box.exceptions.BoxKeyError: "'GraphQLResult' object has no attribute 'core_version'"

This PR fixes that.

Thanks for your time and consideration!

Changes

Changes to utilities.agent.get_flow_run_command() to use getattr() when looking for core_version in a flow_run.

Importance

I discovered this PR while running the unit tests for a custom KubernetesAgent that I've written with some my-company-specific logic. I was mocking the flow_run contents and hadn't included core_version. Others doing that might face this issue, and this PR will mitigate it.

I'm not that familiar with GraphQL, so I don't know if you're guaranteed to get {"core_version": null} in the response if you ask for that field. If you aren't, then other people running versions of core that don't return this field would also face this issue without this fix.

Checklist

  • adds new tests (if appropriate)
  • adds a change file in the changes/ directory (if appropriate)
  • updates docstrings for any new functions or function arguments, including docs/outline.toml for API reference docs (if appropriate)

@codecov
Copy link

codecov bot commented Aug 17, 2020

Codecov Report

Merging #3177 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Copy link

@joshmeek joshmeek left a comment

Choose a reason for hiding this comment

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

Thanks @jameslamb!

@joshmeek joshmeek merged commit 8e7b048 into PrefectHQ:master Aug 17, 2020
@jameslamb jameslamb deleted the fix/core-version branch September 15, 2020 20:15
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.

None yet

2 participants