-
Notifications
You must be signed in to change notification settings - Fork 61
update base model and add as_dict support for base model #2027
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
Conversation
| _content = resource | ||
| else: | ||
| _content = json.dumps(resource, cls=AzureJSONEncoder) # type: ignore | ||
| _content = json.dumps(resource, cls=AzureJSONEncoder, exclude_readonly=True, exclude_none=False) # type: ignore |
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.
I don't think we should replace it with as_dict bc:
- body could be non model
- body could be a
MutableMapping[str, Any]that mix simpledictandModel json.dumps(Model.as_dict())will go through all models' attributes twice, it is not effiecient
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.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| create_body_call = ( | ||
| f"_{body_kwarg_name} = json.dumps({body_param.client_name}, " | ||
| "cls=AzureJSONEncoder) # type: ignore" | ||
| "cls=AzureJSONEncoder, exclude_readonly=True,\n exclude_none=False) # type: ignore" |
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.
we exclude_none True right now, it's just that it's currently handled in the JSON encoder. I feel it'll be clearer if we just pass in True here
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.
I'm a little confused. Let me give an example that you could help to correct:
class TestModel(Model):
prop1: str
prop2: str
prop3: str
model = TestModel({"prop1": None, "prop2": NULL})
json.dumps(model, cls=AzureJSONEncoder, exclude_none=True) # the result should be {"porp2": null}
json.dumps(model, cls=AzureJSONEncoder, exclude_none=False) # test result should be {"prop1": null, "prop2": null}
packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2
Outdated
Show resolved
Hide resolved
| models.update({ | ||
| k: v | ||
| for k, v in sys.modules[module_end].__dict__.items() | ||
| if isinstance(v, (type, typing._GenericAlias)) # type: ignore |
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.
what is this added code for? I don't know if we should access a private model in the typing namespace
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.
It is for type alias like:
union MyNamedUnion {
one: Model1,
two: Model2,
}
resolve #1990
model base change and test is here: Azure/azure-sdk-for-python#31028
also, fix #2034, #2035, #2036