Opened 6 years ago

Closed 3 years ago

#15303 closed Cleanup/optimization (needsinfo)

Clarify View.as_view() docs in respect to functions passed as kwargs.

Reported by: gg Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



At the moment, generic.base.View.as_view() passes kwargs to the class' init (which setattrs them), rather than dynamically subclassing. The introductory generic view docs, however, seem to imply that passing kwargs to the as_view() method is equivalent to overriding the class. For example, it refers to "pass[ing] the new attributes into the as_view method call" as an "overriding pattern." This makes it rather surprising that functions passed to as_view() aren't bound to the resultant instance.

Possible Resolutions:

It seems to me that as_view() should dynamically create a subclass with the provided kwargs. Alternatively, if that is deemed undesirable, the docs should at least be clarified to better explain the true behaviour.

I can provide a patch, but need someone (*cough* RKM :) to confirm the desired behaviour.

Change History (8)

comment:1 Changed 6 years ago by russellm

  • Component changed from Generic views to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

As discussed on IRC: I'm not sure I see why we should make the implementation of the generic view base class a whole lot more complicated in order to allow users to avoid creating a subclass. Passing arguments in to as_view() is a convenience for the really simple cases -- it isn't intended as a way to avoid ever needed to create a View subclass.

However, I can see how the phrasing about "overriding pattern" could lead to this expectation, so that should be cleaned up.

comment:2 Changed 5 years ago by lrekucki

  • Severity set to Normal
  • Summary changed from Functions passed as kwargs to View.as_view() should be bound to Clarify View.as_view() docs in respect to functions passed as kwargs.
  • Type set to Cleanup/optimization

comment:3 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:11 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:12 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:13 Changed 4 years ago by timo

  • Has patch set

Not sure if this patch was in response to this ticket, but this looks related at least:

comment:14 Changed 4 years ago by timo

  • Has patch unset

I've merged the pull request above, but it seems like there may be additional clarification that should be added (not sure what exactly).

comment:15 Changed 3 years ago by timo

  • Resolution set to needsinfo
  • Status changed from new to closed

@gg, if you can provide a patch please reopen. Otherwise, I'm not sure what further clarification (if any) is needed here.

Note: See TracTickets for help on using tickets.
Back to Top