2016-09-15 30 views
1

我有以下型號:Django的1.10全文由UUIDField搜索返回DataError

class Show(models.Model): 
    cid = models.UUIDField(
     default=uuid.uuid4, 
     editable=False, 
     verbose_name="Content ID", 
     help_text="Unique Identifier" 
    ) 
    title_short = models.CharField(
     max_length=60, 
     blank=True, 
     verbose_name="Short Title", 
     help_text="Short title (60 chars)" 
    ) 

我使用下面的代碼片段

from django.contrib.postgres.search import SearchVector 
Entry.objects.annotate(
    search=SearchVector('cid'), 
).filter(search='wateva') 

返回:

DataError at /meta/shows/ 

invalid input syntax for uuid: "" 
LINE 1: ...unt", to_tsvector(COALESCE("entities_show"."cid", '')) AS "s... 

我試着用PostgreSQL 9.3.14和PostgreSQL 9.5.3,Python 3.4.3

有沒有人遇到過這個問題?

回答

1

您可能想要提交錯誤報告。

Django代碼創建一個COALESCE()語句,假定給定字段的空字符串的最終回退值('')是可接受的。 我沒有看到通過官方API指定回退值的方法,並且由於UUID字段已轉換爲Postgres Native UUID字段,因此空字符串對於該字段而言是無效的值。

如果您決定提交報告,請在此處添加評論,並附上票證ID,我可能會解決該問題,因爲我對此功能擁有既得利益。

+1

這是門票: https://code.djangoproject.com/ticket/27227 –