Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28492 closed Cleanup/optimization (fixed)

Allow defining expressions' default output_field as a class attribute rather than in __init__()

Reported by: Mads Jensen Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Simon Charette Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

There are a few expression-classes that override __init__ just to set output_field,

class Extent3D(GeoAggregate):

def __init__(self, expression, **extra):
    super().__init__(expression, output_field=ExtentField(), **extra)

From this comment https://github.com/django/django/pull/7611/files#r131567089 runtests.py needs to be adjusted, so it's possible to use a class-variable for the output field instead.

Change History (5)

comment:1 by Tim Graham, 7 years ago

Cc: Simon Charette added
Has patch: set
Patch needs improvement: set
Summary: output_field in __init__-method of expressionsAllow defining expressions' default output_field as a class attribute rather than in __init__()
Triage Stage: UnreviewedAccepted

Simon has a PR for this.

comment:2 by Tim Graham <timograham@…>, 7 years ago

In 13be4530:

Refs #28492 -- Stopped accessing settings at Field.db_tablespace initialization.

Deferring accesses to settings allows database fields to be initialized before
settings are loaded.

comment:3 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 08654a99:

Fixed #28492 -- Defined default output_field of expressions at the class level.

This wasn't possible when settings were accessed during Field initialization
time as our test suite setup script was triggering imports of expressions
before settings were configured.

comment:4 by Tim Graham <timograham@…>, 7 years ago

In f1b7130:

Refs #28492 -- Defined aggregates' output_field at the class level.

Missed in 08654a99bbdd09049d682ae57cc94241534b29f0.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In deb3b58b:

[2.0.x] Refs #28492 -- Defined aggregates' output_field at the class level.

Missed in 08654a99bbdd09049d682ae57cc94241534b29f0.

Backport of f1b713024e3a1e8c6361ea407cb8248224f7cc82 from master

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