-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow primary key for nested models in OpenAPI request schemas #18451
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
Allow primary key for nested models in OpenAPI request schemas #18451
Conversation
|
@jeremystretch any chance i could get a review here? |
|
Any updates on this? I generated a Go client with these changes and it really looks very good. |
arthanson
left a comment
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.
Just the one simple optimization otherwise looks good.
e97dbe4 to
7216a0d
Compare
|
@mraerino sorry one more minor, there is a merge conflict, can you please fix that. As this code is from a separate repository I can't make the quick fix without creating a new PR. re the syntax change for the walrus operator (:=) not really required - just more concise, in this case can be debatable if it is more readable or not. Generally we use that in newer code (since it is a newer python addition) where applicable, but it was a suggestion so if you feel it is cleaner without I'm okay with that. Also, can you please request re-review (upper right spinner next to name) when you have made the change so it pops up in my queue, makes it easier to track all the incoming PRs. |
|
@arthanson I only know this syntax from Go, and there an assignment within the condition of an if statement is only valid within that if/else block. We use |
I merged main in to fix the conflict. (Funnily it was me who introduced the other change that lead to the conflict.) Did you know that all people with access to this repo are allowed to push to my branch since i checked "Allow edits by maintainers" on this PR?
I'd rather keep the code like it is to avoid confusion about variable scope as pointed out by @hikhvar |
Fixes: #17709
The logic for passing a primary key when specifying a nested model on creation or update is hidden in some special logic in
BaseModelSerializerand cannot be detected bydrf-spectacular.I'm introducing an extension that patches the write request schemas to allow for either the primary key as a number or an object with fields (what was already present).
This aligns the schema with reality.