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

Fail the query with a helpful message if the variables defined do not match the expected values #3856

Merged
merged 4 commits into from
Nov 2, 2020

Conversation

kinow
Copy link
Member

@kinow kinow commented Oct 6, 2020

These changes close #3855

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Appropriate tests are included (unit and/or functional).
  • Appropriate change log entry included.
  • No documentation update required.
  • No dependency changes.

@kinow kinow self-assigned this Oct 6, 2020
@kinow
Copy link
Member Author

kinow commented Oct 6, 2020

Now if I accidentally misspell a variable in Cylc UI, the message should hint that there's something wrong with the variables.

image

And fixing the variables then the query runs just fine.

image

@kinow
Copy link
Member Author

kinow commented Oct 6, 2020

Virtual memory error when running the bash tests in the Docker container. Fix available in #3854

Will spend some more time on this later trying to add a test. Not sure if a unit test will work, might try our new test classes for the first time 👍

@kinow
Copy link
Member Author

kinow commented Oct 7, 2020

The other PR that contains the fix for the Docker builds may take a while to be merged, while we wait for GH Actions to include Python 3.9.

So I've cherry-picked the commit that should fix Docker, and pushed here 👍

@kinow
Copy link
Member Author

kinow commented Oct 8, 2020

Functional test broadcast/00-simple is failing, but I think it needs to be updated after this fix (just need to understand how it works, and confirm it indeed just needs to be updated)

@kinow kinow force-pushed the useful-variable-error-message branch from 577e8fa to 1b210b6 Compare October 12, 2020 20:57
@kinow
Copy link
Member Author

kinow commented Oct 13, 2020

Added a unit test, and the changelog. Confirmed locally with coverage + pytest that the unit test covered the change in the network.graphql module 👍

Existing functional tests cover that function already, though partially.

@kinow kinow marked this pull request as ready for review October 13, 2020 22:03
@kinow
Copy link
Member Author

kinow commented Oct 13, 2020

I fixed the functional test in this PR, and yesterday it passed in the Docker image. Strangely, it failed now, but my only updates were changelog and a new unit test. 🤔 ready for review, I think the test is just a bit brittle in Docker (will investigate why later)

@kinow kinow added this to the cylc-8.0a3 milestone Oct 13, 2020
Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

LGTM, but I'll defer to @dwsutherland for the definitive review.

Copy link
Member

@dwsutherland dwsutherland left a comment

Choose a reason for hiding this comment

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

Good idea @kinow , may I suggest the following instead:

        for defn in document_ast.definitions:
            if isinstance(defn, ast.OperationDefinition):
                root_type = get_operation_root_type(schema, defn)
                definition_variables = defn.variable_definitions or []
                if definition_variables:
                    def_var_names = {
                        v.variable.name.value
                        for v in definition_variables
                    }
                    var_names_diff = def_var_names.difference({
                        k
                        for k in variable_values
                        if k in def_var_names
                    })
                    # check if we are missing some of the definition variables
                    if var_names_diff:
                        msg = (f'Please check your query variables. The '
                               f'following variables are missing: '
                               f'[{", ".join(var_names_diff)}]')
                        raise ValueError(msg)
                self.operation_defs[getattr(defn.name, 'value', root_type)] = {
                    'definition': defn,
                    'parent_type': root_type,
                    'variables': get_variable_values(
                        schema,
                        definition_variables,
                        variable_values
                    ),
                }
            elif isinstance(defn, ast.FragmentDefinition):
                self.fragment_defs[defn.name.value] = defn

Then you don't have to change the default behaviour of GraphQL (i.e. if None is desirable to fall to the schema defined default), and hence not have to change the CLI tests.

@kinow
Copy link
Member Author

kinow commented Oct 31, 2020

Good idea @kinow , may I suggest the following instead:

Then you don't have to change the default behaviour of GraphQL (i.e. if None is desirable to fall to the schema defined default), and hence not have to change the CLI tests.

Hi @dwsutherland ! Thanks for the suggestion! I will just need some time tomorrow to re-contextualize with the change, and understand your change. Then it should be a matter of just updating the PR with a new/edit commit, and check if tests pass 👍

Might be able to complete it before the executive roadshow starts tomorrow in Auckland, by the morning.

@kinow kinow force-pushed the useful-variable-error-message branch from 2871380 to b140920 Compare November 1, 2020 20:26
@kinow
Copy link
Member Author

kinow commented Nov 1, 2020

Fixed git conflicts, and applied @dwsutherland 's patch (thanks!). I think we now just need to wait for CI to verify.

@kinow kinow force-pushed the useful-variable-error-message branch from b140920 to e1a23f5 Compare November 2, 2020 02:17
Copy link
Member

@dwsutherland dwsutherland left a comment

Choose a reason for hiding this comment

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

Good to go 👍

@dwsutherland dwsutherland merged commit 77c781a into cylc:master Nov 2, 2020
@kinow kinow deleted the useful-variable-error-message branch November 2, 2020 04:32
@hjoliver hjoliver modified the milestones: cylc-8.0a3, cylc-8.0b0 Feb 25, 2021
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.

[graphql] Error running query: argument of type 'NoneType' is not iterable
3 participants