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

two imports with the same import-name are not distinguised #145

Closed
FlorianLudwig opened this issue Jun 11, 2020 · 10 comments
Closed

two imports with the same import-name are not distinguised #145

FlorianLudwig opened this issue Jun 11, 2020 · 10 comments
Assignees
Labels
bug Something isn't working released

Comments

@FlorianLudwig
Copy link
Contributor

Describe the bug
I am not yet sure how to reproduce which state, as I have two different observation:

Example 1:

Generated code:

from ...apimachinery.pkg.apis.meta import v1
from ..core import v1

(from: https://github.com/FlorianLudwig/pdk8s/blob/e9b5903c4f8cf584fe60a4a84709a42f7e63b771/pdk8s/gen/io/k8s/api/networking/v1beta1.py#L12)

Example 2:

Generated code:

from ...apimachinery.pkg.apis.meta import v1
from ..core import v1 as v1_1

(from: https://github.com/FlorianLudwig/pdk8s/blob/e9b5903c4f8cf584fe60a4a84709a42f7e63b771/pdk8s/gen/io/k8s/api/extensions/v1beta1.py)

In this example, the second import is renamed to avoid the collision but the references are not. Resulting in code trying to access module members that are in v1_1 but refer to v1. (Example)

Expected behavior

The second example is a step in the right direction (or maybe import more of the package name, in this example meta.v1 instead of just v1). But the references must be updated.

Version:

  • datamodel-code-generator: git master
@koxudaxi
Copy link
Owner

@FlorianLudwig
Thank you for your report
OK, I will research the problem.
I want to fix easy. but, we may need to refactor resolving class logic.

@koxudaxi koxudaxi self-assigned this Jun 15, 2020
@koxudaxi
Copy link
Owner

I just understood that I have to refactor the logic of referencing and resolving classes.
I hope to do it in this week or next week.

@FlorianLudwig
Copy link
Contributor Author

Thank you so much for your work! Looking forward to it.

@koxudaxi
Copy link
Owner

koxudaxi commented Jun 28, 2020

Sorry, I'm busy this week.
I want to get the time next week.

@koxudaxi
Copy link
Owner

@FlorianLudwig
I have fixed it and released a new version as 0.5.16

@FlorianLudwig
Copy link
Contributor Author

FlorianLudwig commented Jul 21, 2020

Hi @koxudaxi,

I just tested 0.5.16 and it seems like a regression to me.

Previously:

  • name clashes of module - problem
  • name clashes of class names - not a problem

Now:

  • name clashes of module - not a problem
  • name clashes of class names - problem

All but one enum are gone (diff of generated code: left old version, right after upgrade):
image

image

And the same enum is used everywhere.

Files:

edit: link to schema used was the wrong one

@koxudaxi
Copy link
Owner

@FlorianLudwig
Thank you for the details of the problem.
Sorry, I have fixed and released a new version as 0.5.17
Also, I added a unittest for the case.

@FlorianLudwig
Copy link
Contributor Author

Hey @koxudaxi

thanks!

I tested against current master. Looks good!

(It looks like you didn't publish to pypi though)

@koxudaxi
Copy link
Owner

@FlorianLudwig
Thank you for your report.

(It looks like you didn't publish to pypi though)

Really? 🤔
I can look for some new versions in pypi.
https://pypi.org/project/datamodel-code-generator/#history

@FlorianLudwig
Copy link
Contributor Author

FlorianLudwig commented Jul 28, 2020

This is strange. I had the following error with poetry:

Because pdk8s depends on datamodel-code-generator (0.5.17) which doesn't match any versions, version solving failed.

Not sure what I did wrong, but is working now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants