-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fix: Validate and handle invalid extra field in connections UI and API (#53963)
#54034
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: Validate and handle invalid extra field in connections UI and API (#53963)
#54034
Conversation
shubhamraj-git
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Airflow 2.x supported "" in extra parameter for connection and is still supported from the airflow cli. Since upcoming airflowctl would use APIs, I think problem would come if someone tries to import connections from older version of airflow, breaking compatibility. We might need to handle that.
Thanks for flagging @shubhamraj-git! This could indeed be a problem and needs to be handled. This will highly likely reduce the migration effort too if we have backwards compatibility and allow users to migrate their connections to v3. TLDR |
|
If this won't be supported from UI, we may consider dropping the feature from airflow CLI, since if those are imported from CLI, they can end up with some API/UI problems while updates and people can think, this is allowed. If it isn't supported by the API/UI, this shouldn't be allowed from the CLI either, where we can also add small things there if it wasn't deprecated. While more isolation is ongoing, it can be easier to follow up a single source of truth for these kinds of database activities |
|
@bugraoz93 I think it would be hard to drop the functionality to support empty string, since users might have a lot of connection and might end up getting failed imports, which could be a problem. We already had some issue reported in 3.0.0, I think we can give an exception to the empty string, anyways we are supporting to edit an empty string in extra due to the issue mentioned. |
I haven't meant to drop supporting it but rather storing in the database in a unified way. I support backwards compatibility importing from older versions to newer versions for a smooth transition but this doesn't necessarily mean they will be persisted as the default empty string. This means export from a newer version can work on newer versions. It could be even invisible to users if they aren't reading newsletters before updates or following up on database changes. If there is a lot of automation on it across users, we may be even more relaxed about it, I am not against that. |
|
ohh, you meant to transform the empty string to empty json upon migration and not allow creation with empty string via CLI to sync with the behaviour of UI. |
|
Coming along here after being a bit off from PC: I think only valid JSON is of any use in providers. I am not sure if an empty string is used in the providers... which would be against the idea of the extras. To come around the problem of "legacy data" where potentially empty strings are used... I'd propose to ignore just empty strings and either convert them to |
|
@jscheffl @shubhamraj-git @bugraoz93 Thank you for inputs; what we understood is we have to allow support for '' in api to support backward compatibility for ctl. so we should convert '' to {} before storing in DB while from UI; we could restrict even '' | OR | to be in sync till airflow 4; we can allow '' from UI also; and since api already converting it to {} Now; we also need to add deprecation log in
Please confirm if our approach is okay! P.S> @Prasanth345 is actively working on this ticket. I am just giving pair of eyes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes if the problem is only accepting empty string for backward compatiblity. We can just handle it in the serializers (ConnectionResponse and ConnectionBody) with a warning / message as jens mentionned.
:param extra: Extra metadata. Non-standard data such as private/SSH keys can be saved here. JSON
encoded object.
Also can you add some backend test to demonstrate that we can send "" successfully.
airflow-core/src/airflow/api_fastapi/core_api/datamodels/connections.py
Outdated
Show resolved
Hide resolved
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, LGTM for the API part.
Only small nits for having "" to wrap the extra` field, but no strong opinion for this, just personal preference.
airflow-core/src/airflow/api_fastapi/core_api/datamodels/connections.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/datamodels/connections.py
Outdated
Show resolved
Hide resolved
|
Addressed backward compatibility for Added validation to ensure Also tested changes using |
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, it's almost ready to be merged!
Static check for the following files need fix:
airflow-core/src/airflow/ui/src/pages/Connections/ConnectionForm.tsxairflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
https://github.com/apache/airflow/actions/runs/16749342479/job/47415914322?pr=54034
They should be automatically fixed by running pre-commit again.
1a1f4a2 to
0adeadd
Compare
0adeadd to
4df5c8c
Compare
|
@jason810496 fixed the static check errors |
|
Yes, I agree with Jens here and with comments from Pierre and Liu Zhe You. This is exactly what I mentioned: we should set it as either |
bugraoz93
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…API (apache#53963) (apache#54034) * Validate and handle non-dict JSON in field for connections * Handle empty string in field for backward compatibility and add validation --------- Co-authored-by: lakshminarayana.kumbha <lakshminarayana.kumbha@zemosolabs.com> (cherry picked from commit 8e1e3bb)
…API (#53963) (#54034) (#54235) * Validate and handle non-dict JSON in field for connections * Handle empty string in field for backward compatibility and add validation --------- (cherry picked from commit 8e1e3bb) Co-authored-by: Kumbha Lakshmi Narayana <58362993+Prasanth345@users.noreply.github.com> Co-authored-by: lakshminarayana.kumbha <lakshminarayana.kumbha@zemosolabs.com>
…API (apache#53963) (apache#54034) * Validate and handle non-dict JSON in field for connections * Handle empty string in field for backward compatibility and add validation --------- Co-authored-by: lakshminarayana.kumbha <lakshminarayana.kumbha@zemosolabs.com>
|
Cool! Thanks for the contribution! |
This PR addresses issue #53963 by ensuring the
extrafield in connections is always a valid JSON object, both in the UI and backend.Summary of Changes
Frontend (
ConnectionForm):extravalues that are not JSON objects (e.g.,"abc",[],123).Backend (
ConnectionBodyschema):extrais a JSON-encoded Pythondict.extrais invalid or not a dict, the API now returns a 422 Unprocessable Entity with a descriptive error message instead of crashing with a 500.Backend (
_mask_connection_fields):extrafield..items()call on string/array and returns a fallback message instead.Related Issue
Closes #53963