Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#22626 closed Bug (fixed)

SQLite's DatabaseSchemaEditor.quote_value trips on buffer and memoryview instances

Reported by: loic84 Owned by: xelnor
Component: Database layer (models, ORM) Version: 1.7-beta-2
Severity: Release blocker Keywords:
Cc: andrewgodwin 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

Since e9a456d11b5b63389b466ed435ef3915f0e79e4c default values for migrations go through get_db_prep_save() which in case of BinaryField results in buffer (PY2) or memoryview (PY3) instances. This causes a ValueError since quote_value() doesn't specifically support these types: https://github.com/django/django/blob/master/django/db/backends/sqlite3/schema.py#L32.

The test case for #22424 (https://github.com/django/django/pull/2634) demonstrates the issue.

Dunno if it's relevant but the Oracle backend falls back to str rather than raising an exception: https://github.com/django/django/blob/master/django/db/backends/oracle/schema.py#L28

Change History (7)

comment:1 Changed 14 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from master to 1.7-beta-2

comment:2 Changed 14 months ago by xelnor

  • Owner changed from nobody to xelnor
  • Status changed from new to assigned

comment:3 Changed 14 months ago by xelnor

  • Has patch set

A full patch including test has been added at https://github.com/django/django/pull/2670 (pull request against stable/1.7.x).

This patch also fixes a slight issue in the SQLite backend when re-making a table: default values for new fields where incorrectly quoted with "column name" quoting rules.

comment:4 Changed 14 months ago by xelnor

  • Triage Stage changed from Accepted to Ready for checkin

I've updated the patch, which has been reviewed by shai.

Marking "Ready for Checkin" with his benediction.

comment:5 Changed 14 months ago by loic84

I've added this commit to the PR for #22424: https://github.com/django/django/pull/2634.

comment:6 Changed 14 months ago by Loic Bistuer <loic.bistuer@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 6aacb4c9915c83a897dbde0b11cc46131fc7d16e:

Fixed #22626 -- Allow BinaryField defaults with SQlite.

Also fixes a slight issue in sqlite3.schema._remake_table where
default values where quoted with "column name" quoting rules.

Reference for quoting: http://www.sqlite.org/lang_expr.html

Thanks Shai Berger for the review. Refs #22424.

comment:7 Changed 14 months ago by Tim Graham <timograham@…>

In 1a29675d76de00d6fad9b366fc66e8b6d541c3b6:

[1.7.x] Fixed #22626 -- Allow BinaryField defaults with SQlite.

Also fixes a slight issue in sqlite3.schema._remake_table where
default values where quoted with "column name" quoting rules.

Reference for quoting: http://www.sqlite.org/lang_expr.html

Thanks Shai Berger for the review. Refs #22424.

Backport of 6aacb4c991 from master

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