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

[bug][python][model] Should not import self #7541

Open
wy-z opened this issue Jan 31, 2018 · 8 comments
Open

[bug][python][model] Should not import self #7541

wy-z opened this issue Jan 31, 2018 · 8 comments

Comments

@wy-z
Copy link
Contributor

wy-z commented Jan 31, 2018

Description

image

Swagger-codegen version

2.3.1

Swagger declaration file content or url
"PlacementNode": {
    "type": "object",
    "title": "PlacementNode",
    "properties": {
        "create": {
            "type": "string",
            "format": "date-time"
        },
        "id": {
            "type": "integer",
            "format": "int64"
        },
        "name": {
            "type": "string"
        },
        "parent": {
            "$ref": "#/definitions/PlacementNode"
        },
        "type": {
            "type": "string"
        },
        "update": {
            "type": "string",
            "format": "date-time"
        }
    }
}
Command line used for generation

generate -l python

@wy-z wy-z changed the title [python][model] Should not import self [bug][python][model] Should not import self Jan 31, 2018
@gorlins
Copy link

gorlins commented Jan 31, 2018

ran into this too... did not occur in v2.2.3

@jimmyjames
Copy link

Seeing this as well on 2.3.0. Maybe related to #6839? (looking at the generated # noqa: F401,E501 comments introduced there).

@jacobweber
Copy link

Same issue....had to manually remove one of the circular references before building.

@wy-z
Copy link
Contributor Author

wy-z commented Mar 14, 2018

@jacobweber Try #7542, It works for me~

@tomplus
Copy link
Contributor

tomplus commented Mar 22, 2018

In my opinion we should remove these imports from models. It makes a lot of problems with circular dependencies between 2 or more models (model A has an attribute with model B and model B has a optional attribute with model A). These imported objects are not used at all and we know about it - we added F401 to disable warning from pylint :/

@macks22
Copy link

macks22 commented Sep 15, 2018

Didn't have time to make any contributions to the referenced PR, but I made a gist that can be used to comment out the problematic lines after the code is generated. Hopefully this can be useful for those still dealing with this problem.

https://gist.github.com/macks22/a087cce914090b4a5d3a16e8ab3c28aa

@erraggy
Copy link

erraggy commented Oct 9, 2018

In my opinion we should remove these imports from models. It makes a lot of problems with circular dependencies between 2 or more models (model A has an attribute with model B and model B has a optional attribute with model A).

YES

Please remove the imports for parent/child referenced types as they do in fact cause runtime errors from circular imports!
PLEASE

@Sarek-Wyona
Copy link

We currently have data models that use other data types as part of their definition. We are seeing circular imports in this case.

If datatype A uses data type B as a part of one variable type. The import for datatype B is present in the datatype A file (not needed as the type is used only as string or doc string). But then datatype B imports datatype A (causing circular import - again not needed)

I have to manually comment out one of these import statements before my auto-generated client works without an import error!

Is this currently being worked on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants