Opened 4 months ago

Closed 7 days ago

Last modified 7 days ago

#36727 closed Cleanup/optimization (fixed)

Deprecate get_placeholder in favor of get_placeholder_sql

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

Description

For consistency with other expressions that return sql and params separately (e.g. tuple[str, tuple]), we should deprecate get_placeholder for a get_placeholder_sql method that returns tuple[str, tuple] and adapt BaseSpatialField, get_geom_placeholder, and other call sites like Value.as_sql to make use of it.

Change History (9)

comment:1 by Simon Charette, 4 months ago

Owner: set to Simon Charette
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by Simon Charette, 4 months ago

Has patch: set
Patch needs improvement: set

comment:3 by Simon Charette, 4 months ago

Needs documentation: set
Needs tests: set

Made some progress. Once I got the full suite passing I'll add the missing tests and release note docs for the deprecation.

comment:4 by Simon Charette, 3 months ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:5 by Jacob Walls, 3 weeks ago

Patch needs improvement: set

comment:6 by Simon Charette, 10 days ago

Patch needs improvement: unset

comment:7 by Jacob Walls, 7 days ago

Triage Stage: AcceptedReady for checkin

comment:8 by Jacob Walls <jacobtylerwalls@…>, 7 days ago

Resolution: fixed
Status: assignedclosed

In 1a8fd5cf:

Fixed #36727 -- Deprecated Field.get_placeholder in favor of get_placeholder_sql.

The lack of ability of the get_placeholder call chain to return SQL and
parameters separated so they can be mogrified by the backend at execution time
forced implementations to dangerously interpolate potentially user controlled
values.

The get_placeholder_sql name was chosen due to its proximity to the previous
method, but other options such as Field.as_sql were considered but ultimately
rejected due to its different input signature compared to Expression.as_sql
that might have lead to confusion.

There is a lot of overlap between what Field.get_db_prep_value and
get_placeholder_sql do but folding the latter in the former would require
changing its return signature to return expression which is a way more invasive
change than what is proposed here.

Given we always call get_db_prep_value it might still be an avenue worth
exploring in the future to offer a publicly documented interface to allow field
to take an active part in the compilation chain.

Thanks Jacob for the review.

comment:9 by Jacob Walls <jacobtylerwalls@…>, 7 days ago

In d43bd46:

Refs #36727 -- Factored out _must_transform_value() in BaseSpatialOperations.

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