-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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 problem in sanitize_for_serialization for Python (pydantic type SecretStr ) BUG#16086 (2nd pull) #18023
Conversation
@@ -366,7 +371,11 @@ def sanitize_for_serialization(self, obj): | |||
# and attributes which value is not None. | |||
# Convert attribute name to json key in | |||
# model definition for request. | |||
obj_dict = obj.to_dict() | |||
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please remove this extra blank line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please remove this extra blank line?
done
please also review the test failure when you've time: https://github.com/OpenAPITools/openapi-generator/actions/runs/8176114031/job/22463329272?pr=18023 |
Bug 16086
update samples / remove extra blank line
if complains:
I set password as SecretStr: l = LoginTest(username="admin", password=SecretStr("testing09876")) |
@@ -408,7 +408,12 @@ def test_valdiator(self): | |||
self.assertEqual(a.pattern_with_digits_and_delimiter, "image_123") | |||
|
|||
# test sanitize for serializaation with SecretStr (format: password) | |||
self.assertEquals(petstore_api.ApiClient().sanitize_for_serialization(a), {'byte': b'string', 'date': '2013-09-17', 'number': 123.45, 'password': 'testing09876', 'pattern_with_digits_and_delimiter': 'image_123'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding another test below
shouldn't this test/assertion still pass after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this test/assertion still pass after this change?
yes, you are right... it can make sense to keep this line also as in case of password which will be as default string - it will also work. I added this line back to this pull.. 0ed3ba4 + will check sanitize function based on bytes/date/integer data types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 - can you please check and confirm that now is ok?
restore sanitize test for serialization with different data types
cc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…ecretStr ) BUG#16086 (2nd pull) (OpenAPITools#18023) * fix-for-bug-16086 * add to_dict alternative * fix assertEqual * remove extra blank line + test_model Argument SecretStr set * update samples / remove extra blank line * restore sanitize test for serialization with different data types * remove empty line in api_client.mustache * remove 2nd empty line in api_client.mustache
…ng changes from #18023 (#20102) * Apply changes of #18023 * Regenerate samples --------- Co-authored-by: tweber2 <[email protected]>
#16086
handling SecretStr for the password field
this is 2nd pull try
history and more explanation in: #17310
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)