Skip to content

Fix schemas for extra actions - #5992

Merged
carltongibson merged 4 commits into
encode:masterfrom
rpkilby:schema-creation
Jul 6, 2018
Merged

carltongibson merged 4 commits into
encode:masterfrom
rpkilby:schema-creation

Conversation

@rpkilby

@rpkilby rpkilby commented May 17, 2018 •

Copy link
Copy Markdown
Contributor

Ensures that view instances are operating on their own schema instance. Previously, all instances of the class were using a shared, class-level schema instance, and the descriptor was mutating the schema to ensure the most recently accessed view instance was set on the schema.

@carltongibson
carltongibson self-requested a review May 17, 2018 08:01
Comment thread rest_framework/views.py Outdated
# copy class-level schema to prevent instances using the same object
if 'schema' not in self.__dict__:
self.schema = deepcopy(self.schema)
self.schema.view = self

@carltongibson carltongibson May 17, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this in ViewInspector.__get__()? (The goal being to keep the api out out APIView, bar the minimal schema property.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me take a second look at this. It might be possible to do this with __set__

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, updated the descriptor with a setter. This seems to work fine.

@rpkilby rpkilby mentioned this pull request May 17, 2018
6 tasks done

@carltongibson carltongibson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. This looks good. Let me have a play with it and I'll get back to you. 👍

@carltongibson carltongibson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, again, great stuff.

I think we need to add something about the schema argument to @action() to the docs.

@rpkilby
rpkilby force-pushed the schema-creation branch 2 times, most recently from d9b4f63 to f3dd14e Compare June 22, 2018 21:10
@rpkilby

rpkilby commented Jun 22, 2018

Copy link
Copy Markdown
Contributor Author

@carltongibson - rebased/updated the PR. I've opted for a note in the shema docs instead of the viewset docs, given that the latter don't currently mention schemas.

@rpkilby rpkilby added this to the 3.8.3 Release milestone Jun 22, 2018
@carltongibson
carltongibson merged commit 6511b52 into encode:master Jul 6, 2018
@rpkilby
rpkilby deleted the schema-creation branch July 6, 2018 14:08
@rpkilby rpkilby modified the milestones: 3.8.3 Release, 3.9 Release Aug 29, 2018
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Add failing test for extra action schemas

* Add ViewInspector setter to store instances

* Fix schema disabling for extra actions

* Add docs note about disabling schemas for actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants