Skip to content

Conversation

@potiuk
Copy link
Member

@potiuk potiuk commented Dec 12, 2023

The released providers added support to previous version of the airflow.io - where options were not passed to get_fs method that provides Fsspec compatible FileSystem. However #35820 added positional "options" parameter when the method is called and it broke already released providers.

This PR dynamically inspects signature of the get_fs method and when one parameter is detected, it will skip passing options to get_fs method call.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

The released providers added support to previous version of the
`airflow.io` - where options were not passed to `get_fs` method
that provides Fsspec compatible FileSystem. However apache#35820 added
positional "options" parameter when the method is called and it
broke already released providers.

This PR dynamically inspects signature of the get_fs method
and when one parameter is detected, it will skip passing options
to get_fs method call.
parameters = inspect.signature(fs).parameters
if len(parameters) == 1:
return fs(conn_id) # type: ignore[call-arg]
return fs(conn_id, options) # type: ignore[call-arg]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test for the old signature to verify

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me see. It's new code for me :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like there are no tests even for retrieval for providers, if time is of an essence, I'd rather leave it for later. created an issue: #36187

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the typical pythonic way to do this with a try catch? Inspect is expensive.

Copy link
Member Author

@potiuk potiuk Dec 12, 2023

Choose a reason for hiding this comment

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

yeah - it's a bit more expensive, but It happens only once at discovery.

I thought about it too but I decided dointg it more explicitly is better. It is much better to handle (potential) patterns where we add more parameters (which might happen). In this case we will just add elif len() ==2 - it would be difficult to distinguish those cases with exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, this is pretty common pattern in Airflow already. We use inspect and looking at parameters and comparing signatures of methods in quite a numer of places already. I personally see it as much more explicit. But of course nothing prevents us from changing it in the future if we agree it's a better solution, this part is internal and can be changed any time.

@ephraimbuddy ephraimbuddy merged commit 7799c51 into apache:main Dec 12, 2023
@ephraimbuddy ephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-58 labels Dec 12, 2023
@ephraimbuddy ephraimbuddy added this to the Airflow 2.8.0 milestone Dec 12, 2023
ephraimbuddy pushed a commit that referenced this pull request Dec 12, 2023
…6186)

The released providers added support to previous version of the
`airflow.io` - where options were not passed to `get_fs` method
that provides Fsspec compatible FileSystem. However #35820 added
positional "options" parameter when the method is called and it
broke already released providers.

This PR dynamically inspects signature of the get_fs method
and when one parameter is detected, it will skip passing options
to get_fs method call.

(cherry picked from commit 7799c51)
@bolkedebruin
Copy link
Contributor

Mmm yes I understand. Sorry for this, I mentioned when merging the other it would require a release of the providers and wanted to prevent backwards compat check (which is silly imho as the current set of providers cannot work).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-58 changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants