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

Implement API generator and use it on Connection #18934

Closed
wants to merge 1 commit into from

Conversation

uranusjr
Copy link
Member

See #15072, cc @ephraimbuddy

It turns out Connexion performs argument introspection to decide what arguments to pass to an endpoint (a bit like pytest fixtures), so we can't actually make the functions too generic. For example, we must have a parameter named connection_id in various Connection endpoints, but that's obvious specific to Connection and cannot be refactored out. So this two-layer approach is the best I can come up with for now.

I'm not actually convinced myself if this is a good idea (it feels like a ton of architecture that makes code more difficult to understand), but at least now we have something to think about.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Oct 13, 2021
@ashb
Copy link
Member

ashb commented Oct 13, 2021

Connexion seems to be an abandonded project, so we might want to migrate off to some thing else instead of putting more time in to using it?

@potiuk
Copy link
Member

potiuk commented Oct 13, 2021

Connexion seems to be an abandonded project, so we might want to migrate off to some thing else instead of putting more time in to using it?

I'd quite agree.

@kaxil
Copy link
Member

kaxil commented Oct 13, 2021

@ashb
Copy link
Member

ashb commented Oct 13, 2021

Sadly not -- (at least last time I looked) FastAPI is the inverse of what we want when it comes to the schema -- FastAPI creates the OpenAPI schema from the views/models etc, where as we want to specify the schema up front and the implement it

@ashb
Copy link
Member

ashb commented Oct 13, 2021

https://github.com/p1c2u/openapi-core is on my list to look at, but it's still a fairly small project so I wouldn't feel happy with Airflow using it unless we also got one of us to have co-maintainer on the project.

@kaxil
Copy link
Member

kaxil commented Oct 13, 2021

Sadly not -- (at least last time I looked) FastAPI is the inverse of what we want when it comes to the schema -- FastAPI creates the OpenAPI schema from the views/models etc, where as we want to specify the schema up front and the implement it

Oh yeah, forgot about that !! :(

@uranusjr
Copy link
Member Author

Connexion seems to have found some new life recently: spec-first/connexion#1429

But this PR (and the idea of turning the API implementation into structured classes) isn't really that related to Connexion or whatever OpenAPI tool we use; it was mentioned because the implementation hit some restrictions in Connexion and had to avoid some encapsulation to make things work. But this actually has a "nice" side effect that makes our logic encapsulation decoupled to the OpenAPI part, and we wouldn't need to change the extracted classes when we migrate to another OpenAPI implementation. (What will require the class to change is if we switch away from Marshmallow, e.g. use FaskAPI.)

@RobbeSneyders
Copy link

@Ruwann and I have recently joined as maintainers on Connexion, specifically because it is the only mature API-first Python framework. Let us know if we can help out.

@uranusjr
Copy link
Member Author

Any thoughts on the general approach taken here? Again, the abstraction implemented here is not really affected by what OpenAPI implementation we use.

@ephraimbuddy
Copy link
Contributor

Any thoughts on the general approach taken here? Again, the abstraction implemented here is not really affected by what OpenAPI implementation we use.

👍 I like the approach.

@uranusjr uranusjr marked this pull request as ready for review October 19, 2021 22:46
@uranusjr
Copy link
Member Author

Should be ready.

"""

resource_name: str # Name of the resource for display in error messages etc.
instance_index: List[str] # List keys to uniquely select an instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
instance_index: List[str] # List keys to uniquely select an instance.
instance_indices: List[str] # List keys to uniquely select an instance.

Wondering if it should be plural?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a list of indices, but describing an index (in the database sense) to select a unique instance out for comparison (another name I briefly considered was primary_key). But the name is indeed difficult to understand, maybe I'll change it to something like unique_instance_fields. Suggestions are definitely much welcomed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. I prefer the unique_instance_fields

resource_name: str # Name of the resource for display in error messages etc.
instance_index: List[str] # List keys to uniquely select an instance.

# A list of two-tuples mapping a field's internal name to external (as seen by the user).
Copy link
Contributor

Choose a reason for hiding this comment

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

Dictionary, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I changed the implementation but forgot to update the comment.

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Oct 20, 2021
@ephraimbuddy
Copy link
Contributor

Let's hear from others before merge.

@raphaelauv
Copy link
Contributor

New release with flask2 support -> https://github.com/zalando/connexion/releases/tag/2.10.0

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jan 11, 2022
@github-actions github-actions bot closed this Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API okay to merge It's ok to merge this PR as it does not require more tests stale Stale PRs per the .github/workflows/stale.yml policy file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants