You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "rjgoyln (via GitHub)" <gi...@apache.org> on 2026/04/11 10:28:34 UTC
[PR] add validation for variables import JSON structure [airflow]
rjgoyln opened a new pull request, #65047:
URL: https://github.com/apache/airflow/pull/65047
### Summary
This PR improves validation and error handling for the `variables import` command.
Previously, the implementation assumed that the input JSON was always a dictionary,
which could lead to unexpected `AttributeError` when processing invalid inputs.
This PR introduces explicit validation to ensure safer and more predictable behavior.
---
### Changes
- Validate that the top-level JSON structure is a dictionary
- Enforce presence of `"value"` field for nested variable objects
- Add unit tests to cover invalid input scenarios
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
- [ ] Yes (please specify the tool below)
<!--
Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add validation for variables import JSON structure [airflow]
Posted by "rjgoyln (via GitHub)" <gi...@apache.org>.
rjgoyln commented on PR #65047:
URL: https://github.com/apache/airflow/pull/65047#issuecomment-4231945797
> Maybe just keeping the JSON part to see if it is valid JSON, or not, but that was already handled above.
>
> ```python
> ...
> if not os.path.exists(args.file):
> rich.print(f"[red]Missing variable file: {args.file}")
> sys.exit(1)
> with open(args.file) as var_file:
> try:
> var_json = json.load(var_file)
> except json.JSONDecodeError:
> rich.print(f"[red]Invalid variable file: {args.file}")
> sys.exit(1)
> ...
> ```
>
> I would say let's merge the generic solution for everything and close this. Many thanks for the PR! This could cause confusion, double validation of fields, etc. Or if you think we can somehow combine, open to any ideas :)
Thanks for the feedback! I agree that avoiding double validation and keeping the logic unified is better for the codebase. I’ll close this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add validation for variables import JSON structure [airflow]
Posted by "rjgoyln (via GitHub)" <gi...@apache.org>.
rjgoyln closed pull request #65047: add validation for variables import JSON structure
URL: https://github.com/apache/airflow/pull/65047
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org