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

Modal location aggregation-unit consistency validation masks other validation errors #4816

Closed
jc-harrison opened this issue Jan 20, 2022 · 0 comments
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine

Comments

@jc-harrison
Copy link
Member

jc-harrison commented Jan 20, 2022

Describe the bug
ModalLocationSchema validates that all location sub-queries have the same aggregation unit. However, a validation error in one of the sub-queries will result in the ModalLocationSchema validator attempting to access a non-existent 'aggregation_unit' attribute, and consequently raising an AttributeError instead of ValidationError.

This error message is misleading, as the aggregation unit is not the source of the issue. Also, as the error raised is an AttributeError, not ValidationError, this will result in the server failing to respond to FlowAPI, so a FlowClient user would see a generic "Could not get reply for message" 400 error instead of a helpful message with details of the invalid field.

Product
Flowmachine

To Reproduce

>>> params = {
        'query_kind': 'modal_location',
        'locations': [
            {
                'query_kind': 'daily_location',
                'date': '2016-02-10',
                'aggregation_unit': 'admin3',
                'method': 'invalid-method',
            }
        ]
    }

>>> DailyLocationSchema().load(params["locations"][0])
ValidationError: {'method': ['Must be one of: last, most-common.']}

>>> ModalLocationSchema().load(params)
AttributeError: 'list' object has no attribute 'aggregation_unit'

Expected behavior
Attempting to specify an invalid daily location query as input to a modal location should raise a validation error identifying the invalid parameter.

Additional context
ModalLocationSchema is not the only schema that validates aggregation units in this way - other schemas are likely affected by the same issue.

@jc-harrison jc-harrison added bug Something isn't working FlowMachine Issues related to FlowMachine labels Jan 20, 2022
jc-harrison added a commit that referenced this issue Jul 4, 2022
@mergify mergify bot closed this as completed in 8820019 Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FlowMachine Issues related to FlowMachine
Projects
None yet
Development

No branches or pull requests

1 participant