Skip to content
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 schemas for extra actions #5992

Merged
merged 4 commits into from
Jul 6, 2018
Merged

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented May 17, 2018

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
# 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
Copy link
Collaborator

@carltongibson carltongibson May 17, 2018

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
Member 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
Member 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.

Copy link
Collaborator

@carltongibson carltongibson left a comment

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. 👍

Copy link
Collaborator

@carltongibson carltongibson left a comment

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
Copy link
Member Author

rpkilby commented Jun 22, 2018

@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants