Opened 4 years ago

Closed 4 years ago

#31701 closed Cleanup/optimization (fixed)

Make FileDescriptor subclass DeferredAttribute.

Reported by: Sultan Owned by: Sultan
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Sultan)

The model fields use, by default, the descriptor DeferredAttribute to access and process (if necessary) the data associated with them. This type of data represents the actual data in db column. I prefer to call it a “field data”.

To access the field data in instance dict, Field.attname is used as a key.

In addition to the field data, some other model fields (for example, ForeignKey) also use a "client data" of the attribute, the processing of which is performed by a particular descriptor. Such a descriptor is assigned to a model using Field.name. Its task is to present the same field data in a different format, the result of which differs from the result of Field.attname descriptor: article.author returns a User object, and article.auther_id returns a User object pk.

This feature is not used in FileField. Then why use FileField.name instead of FileField.attname for FileDescriptor?

I think it would be better if FileDescriptor extends the DeferredAttribute class and uses field.attname instead of field.name.

Change History (9)

comment:1 by Sultan, 4 years ago

Description: modified (diff)

comment:2 by Sultan, 4 years ago

Description: modified (diff)
Version: 3.1master

comment:3 by Sultan, 4 years ago

Description: modified (diff)
Summary: Extend DeferredAttribute & Remove unnecessary overriding of contrib_to_class () in FileFieldExtend DeferredAttribute & Remove unnecessary FileField.contrib_to_class ()

comment:4 by Sultan, 4 years ago

Description: modified (diff)

comment:5 by Sultan, 4 years ago

Description: modified (diff)

comment:6 by Mariusz Felisiak, 4 years ago

Owner: changed from nobody to Sultan
Status: newassigned
Summary: Extend DeferredAttribute & Remove unnecessary FileField.contrib_to_class ()Make FileDescriptor subclass DeferredAttribute.
Triage Stage: UnreviewedAccepted

Looks reasonable.

in reply to:  6 comment:7 by Sultan, 4 years ago

Replying to felixxm: It's much better. Thanks.

comment:8 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In a93425a:

Fixed #31701 -- Made FileDescriptor subclass DeferredAttribute.

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