Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#24712 closed Bug (fixed)

UUIDField doesn't work with SQLite3 and Django 1.8

Reported by: Thomas Bétrancourt Owned by: Abhaya Agarwal
Component: Database layer (models, ORM) Version: 1.8
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have the following model with django 1.8:

class File(models.Model):
    uuid = models.UUIDField(_("id"), primary_key=True, default=uuid.uuid4, editable=False)
    path = models.CharField(_("path"), max_length=512)
    parent = models.ForeignKey("Folder", verbose_name=_("parent folder"), related_name="children", blank=True, null=True)
    absent = models.BooleanField(_("absent"), default=False)


class Folder(File):
    pass


class RootFolder(File):
    description = models.TextField(_("description"), blank=True, null=True)


class RootFolderAuthorization(models.Model):
    user = models.ForeignKey(User, verbose_name=_("user"), related_name="folders", blank=True, null=True)
    group = models.ForeignKey(Group, verbose_name=_("group"), related_name="folders", blank=True, null=True)
    folder = models.ForeignKey(RootFolder, verbose_name=_("folder"), related_name="authorizations")
    can_read = models.BooleanField(_("read access"), default=True)
    can_write = models.BooleanField(_("write access"), default=False)


class IncomingFolder(RootFolder):
    pass


class OutgoingFolder(RootFolder):
    url = models.CharField(_("url"), max_length=512)
    username = models.CharField(_("username"), max_length=32, blank=True, null=True)
    password = models.CharField(_("password"), max_length=128, blank=True, null=True)

When i try to create a new "IncomingFolder", i have the following output:

$ ./manage.py shell
Python 2.7.9 (default, Dec 11 2014, 04:42:00) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from ft_node.models import IncomingFolder
>>> f = IncomingFolder()
>>> f.path = "/var/tmp/in1"
>>> f.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/base.py", line 710, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/base.py", line 738, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/base.py", line 803, in _save_table
    forced_update)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/base.py", line 840, in _do_update
    return update_fields is not None or filtered.exists()
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/query.py", line 586, in exists
    return self.query.has_results(using=self.db)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/sql/query.py", line 479, in has_results
    return compiler.has_results()
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 808, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 837, in execute_sql
    cursor.execute(sql, params)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/thomas.xxx/Documents/Work/Applications/01-Developpement/file-transfer/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
    return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 0 - probably unsupported type.
>>> 

The same model works with MySQL.

I installed django from git master branch (1.9) and it works too.

I tried to install django 1.8 from the stable/1.8.x branch and it doesn't work neither.

Change History (6)

comment:1 Changed 4 years ago by Baptiste Mispelon

Triage Stage: UnreviewedAccepted

Hi,

I can reproduce the issue and using git bisect I found that commit b68212f539f206679580afbfd008e7d329c9cd31 seems to have fixed it (though it doesn't appear related at first sight).

Thanks.

comment:2 Changed 4 years ago by Baptiste Mispelon

I've trimmed down the models to this configuration:

import uuid
from django.db import models


class Foo(models.Model):
    uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)


class Bar(Foo):
    pass


class Baz(Bar):
    pass

With these models, doing Baz().save() triggers the reported error.

comment:3 Changed 4 years ago by Tim Graham

Severity: NormalRelease blocker

It might be a duplicate of #24698 which was also fixed by the bisected commit.

comment:4 Changed 4 years ago by Abhaya Agarwal

Owner: changed from nobody to Abhaya Agarwal
Status: newassigned

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 290c9d6:

[1.8.x] Fixed #24698, #24712 -- Added ForeignKey.get_db_prep_value()

Fixed crashes with ForeignKey to UUIDField and inheritance with UUIDField
primary keys.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 7c7b855:

[1.8.x] Refs #24698, #24712 -- Forwardported ForeignKey.get_db_prep_value() test and release notes.

Fixed in master by b68212f539f206679580afbfd008e7d329c9cd31.

Forwardport of 290c9d665490d80b0a1b648fb022190d7dc375fc from stable/1.8.x

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