Skip to content

Binding context params via values_*() and iterator() methods  #1

@marcinn

Description

@marcinn

Currently there is possibility to bind extra context parameters via keyword args of .values(), .values_list(), .iterator(), .dictiterator() and .scalar() methods. This is quite useful, but:

  • passing extra kwargs makes a hidden copy of the TemplateQuery object, which can't be retrieved because .values*() methods returns a SQLResult-like classes
  • while refactoring a code the mistakes are quite easy to get, when wrapping queries as a context vars for outer templates (outer = sqltemplate.get('outer.sql).values(sql=inner.values(some_arg=1))- please look at usage of .values())
  • the interface of .values() and .values_list() are quite different from Django's QuerySet similar methods

Possibe solutions:

  • make .values() similar to Django' methods by auto-wrapping original query with something like select {{ columns|join:"," }} from ({{ sql|safe }}) x (beware of SQL dialects)
  • let the .values() returns a lazy result contained within a cloned TemplateQuery object to allow embedding (as a solution for refactoring issue)
  • do not allow to modify context by .values()-like methods

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions