Changes between Initial Version and Version 1 of Ticket #35575, comment 6


Ignore:
Timestamp:
Jul 3, 2024, 5:19:58 PM (5 months ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35575, comment 6

    initial v1  
    11I feel like we should avoid the naive approach of calling `refresh_from_db(fields=generated_fields)` as that will mutate the in-memory instance and leave it in this form as well as perform an extra query per constraint.
    22
    3 What should be done IMO is for the query performed in `UniqueConstraint` to call `replace_expressions({F(gfield.name): gfield.expression.replace_expressions(....) for gfield in generated_field})` so that will turn things like
     3What should be done IMO is for the query performed in `UniqueConstraint` to call `replace_expressions({F(gfield.name): gfield.expression.replace_expressions(....) for gfield in generated_field})` so that will make
    44
    55
     
    1616            UniqueConstraint(names="unique_full_name", MD5("full_name"))
    1717        }
     18
     19Contributor(first_name='Mark', last_name='Gensler').full_clean()
    1820}}}
    1921
    20 Then the query to full clean the unique constraint, assuming `first_name` and `last_name` are available, would be
     22result in the following the query, assuming `first_name` and `last_name` are available, would be
    2123
    2224{{{#!sql
    2325SELECT 1 FROM contributor
    24 WHERE md5(lower("first_name" || ' ' || "last_name")) = md5(lower('Mark' || ' ' || 'Gensler')
     26WHERE md5(lower("first_name" || ' ' || "last_name")) = md5(lower('Mark' || ' ' || 'Gensler'))
    2527}}}
    2628
    2729The more we push to the database the less likely we are to run into race conditions and serde roudtrip issues.
     30
     31Note that **this isn't a problem only for UniqueConstraint** all `BaseConstraint` subclasses are affected.
Back to Top