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

fix!: python models not handling circular model dependencies #1946

Merged
merged 4 commits into from
Apr 25, 2024

Conversation

jonaslagoni
Copy link
Member

@jonaslagoni jonaslagoni commented Apr 19, 2024

Description

This PR fixes two major problems with the Python generator; self-referencing models give errors and circular model dependencies do not work.

Self-referencing models

If a model depends on itself the current dependency setup will not work in Python. This fixes it by changing the import style to using forward references (forward references: when a type hint contains names that have not been defined yet, that definition needs to be expressed as a string literal;) through the new Postponed Evaluation of Annotations.

I tried to experiment with all kinds of different solutions, such as those highlighted here: https://stackoverflow.com/a/55344418/6803886

However, this one was the most straightforward solution. It does mean that we add the requirement of using at least Python 3.7, which is why this is breaking.

Circular model dependencies

If we have two models, that each other reference each other in a circular manner Python will complain about it because of the current import style. Going forward we only support explicit import style to allow for this use-case.

Related Issues

Fixes #1940
Fixes #1814

Copy link

netlify bot commented Apr 19, 2024

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 9cb400b
🔍 Latest deploy log https://app.netlify.com/sites/modelina/deploys/66290c4f4e2f56000955f417

@jonaslagoni jonaslagoni changed the title fix: python models not handling circular model dependencies fix!: python models not handling circular model dependencies Apr 24, 2024
@jonaslagoni jonaslagoni marked this pull request as ready for review April 24, 2024 10:40
@jonaslagoni jonaslagoni marked this pull request as draft April 24, 2024 10:47
@jonaslagoni jonaslagoni marked this pull request as ready for review April 24, 2024 13:43
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@jonaslagoni jonaslagoni merged commit da14682 into asyncapi:next Apr 25, 2024
25 checks passed
@jonaslagoni jonaslagoni deleted the fix_python_circular_dependency branch April 25, 2024 12:05
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 4.0.0-next.34 🎉

The release is available on:

Your semantic-release bot 📦🚀

jonaslagoni added a commit to jonaslagoni/generator-model-sdk that referenced this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants