Fix setting non-string initial data from a callable.

Review Request #12278 — Created May 14, 2022 and submitted

Information

Django Evolution
release-2.x

Reviewers

When changing a field's NULL constraint from true to false and
setting the initial data, database evolver backends were assuming the
data being set could be injected directly into the query in the
database. This was often valid, but fell down for more complex types
(like dates/datetimes).

We now accept setting a string directly (for compatibility), but
anything else gets turned into a %s with the value going into the SQL
parameter list.

This ensures that the database layer can properly pass in the data type
in a way that the backend will like.

Unit tests pass for all versions of Django on all database types.

Summary ID
Fix setting non-string initial data from a callable.
When changing a field's NULL constraint from `true` to `false` and setting the initial data, database evolver backends were assuming the data being set could be injected directly into the query in the database. This was often valid, but fell down for more complex types (like dates/datetimes). We now accept setting a string directly (for compatibility), but anything else gets turned into a `%s` with the value going into the SQL parameter list. This ensures that the database layer can properly pass in the data type in a way that the backend will like.
ad79dabb1acc998719d0aab0062ff6a8336b87aa
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.x (1cfc371)