Skip to content

Non-deterministic Import Ordering #459

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

Closed
bolbken opened this issue Jul 28, 2021 · 3 comments
Closed

Non-deterministic Import Ordering #459

bolbken opened this issue Jul 28, 2021 · 3 comments
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers

Comments

@bolbken
Copy link

bolbken commented Jul 28, 2021

Describe the bug
The update command when executed with an unchanged openapi yaml file multiple times results in template model and operation files with different orders of imports at the top of the file. If the resulting client is stored in a git repository, this causes unecessary differences between commits. "Non-deterministic" is intended in the meaning of the order of the imports rather than the set which appears to be the same regardless of the number of update commands.

To Reproduce
Steps to reproduce the behavior:

  1. Generate a client from an openapi yaml file.
  2. Commit the output client to a git repo (optional, but makes the symptom easier to see)
  3. Update a client from the same, unchanged openapi yaml file.
  4. Run a git diff to see the changed import ordering (usually in almost every generated file)

Expected behavior
An order-preserved set of import statements for each generated file.

OpenAPI Spec File
Any OpenAPI yaml file.

Desktop (please complete the following information):

  • OS: Ubuntu Desktop 20
  • Python Version: 3.8.x
  • openapi-python-client version: 0.10.1 ( using pipx run openapi-python-client )
@bolbken bolbken added the 🐞bug Something isn't working label Jul 28, 2021
@dbanty
Copy link
Collaborator

dbanty commented Jul 28, 2021

Probably want to just run isort on the output like we do black. Not an elegant solution but it would be easy to implement.

@bolbken
Copy link
Author

bolbken commented Jul 29, 2021

Agreed. For now I can run that myself in my own repo as a precommit hook or something.

Definitely could be a "good first issue" with your elegant solution.

@dbanty dbanty added the 👋 good first issue Good for newcomers label Jul 29, 2021
@dbanty
Copy link
Collaborator

dbanty commented Sep 5, 2021

@bolbken it turns out we are already using isort it's just that the suggestion of how to run with pipx ensured that isort never ran 😬. I'm updating the instructions for 0.10.4 to make it possible to work, as well as adding in the option to specify your own post-generation hooks. See #479

@dbanty dbanty closed this as completed Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants