Opened 3 months ago

Closed 2 months ago

Last modified 7 weeks 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: master
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 Changed 3 months ago by Tim Graham

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 Changed 2 months ago by Tim Graham <timograham@…>

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 Changed 2 months ago by Tim Graham <timograham@…>

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 Changed 7 weeks ago by Tim Graham <timograham@…>

In f1b7130:

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

Missed in 08654a99bbdd09049d682ae57cc94241534b29f0.

comment:5 Changed 7 weeks ago by Tim Graham <timograham@…>

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