add validation for variables import JSON structure#65047
add validation for variables import JSON structure#65047rjgoyln wants to merge 2 commits intoapache:mainfrom
Conversation
bugraoz93
left a comment
There was a problem hiding this comment.
Maybe just keeping the JSON part to see if it is valid JSON, or not, but that was already handled above.
...
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. |
Summary
This PR improves validation and error handling for the
variables importcommand.Previously, the implementation assumed that the input JSON was always a dictionary,
which could lead to unexpected
AttributeErrorwhen processing invalid inputs.This PR introduces explicit validation to ensure safer and more predictable behavior.
Changes
"value"field for nested variable objectsWas generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.