Skip to content

[Python] Improve model equality implementation#4663

Merged
wing328 merged 2 commits intoswagger-api:masterfrom
mailmojo:fix-python-model-eq
Jan 27, 2017
Merged

[Python] Improve model equality implementation#4663
wing328 merged 2 commits intoswagger-api:masterfrom
mailmojo:fix-python-model-eq

Conversation

@fdanielsen
Copy link
Copy Markdown
Contributor

The model equality implementation template blindly tried accessing the __dict__ attribute of the variable to compare equality against. This attribute does not exist for a lot of Python built-in types (None, str etc.) and the equality check would simply crash.

This adds a simple guard to only continue with equality check if the variable to compare is an instance of the model being compared against.

PR checklist

  • Read the contribution guildelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

Simple update to the Python model mustache template to improve model equality check implementation.

The model equality implementation template blindly tried accessing the
`__dict__` attribute of the variable to compare equality against. This
attribute does not exist for a lot of Python built-in types (`None`,
`str` etc.) and the equality check would simply crash.

This adds a simple guard to only continue with equality check if the
variable to compare is an instance of the model being compared against.
@wing328
Copy link
Copy Markdown
Contributor

wing328 commented Jan 27, 2017

@fdanielsen thanks for the PR. The change looks good to me. I'll merge it later today if no one has any feedback/question.

cc @scottrw93

@frol
Copy link
Copy Markdown
Contributor

frol commented Jan 27, 2017

This PR looks good to me also.

@wing328
Copy link
Copy Markdown
Contributor

wing328 commented Jan 27, 2017

@frol thanks for reviewing the change 👍

PR merged into master. Thanks for the contribution from @fdanielsen

@wing328 wing328 merged commit 3236ade into swagger-api:master Jan 27, 2017
davidgri pushed a commit to davidgri/swagger-codegen that referenced this pull request May 11, 2017
* [Python] Improve model equality implementation

The model equality implementation template blindly tried accessing the
`__dict__` attribute of the variable to compare equality against. This
attribute does not exist for a lot of Python built-in types (`None`,
`str` etc.) and the equality check would simply crash.

This adds a simple guard to only continue with equality check if the
variable to compare is an instance of the model being compared against.

* Remove wrong auto-update of Python requirements
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.

3 participants