#30446 closed Cleanup/optimization (fixed)
Automatically resolve Value's output_field for stdlib types.
Reported by: | Ozan Gerdaneri | Owned by: | Simon Charette |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | SearchVector, SearchVectorField, Value |
Cc: | Matt Westcott, Sergey Fedoseev | 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
Hi,
I have a model of AModel. AModel has a SearchVectorField named search_vector. I want to update this vector by indexing a string that is not in any other field.
from django.db.models import Value from django.contrib.postgres.search import SearchVector AModel.objects.filter(pk=1).update(search_vector=SearchVector(Value("a string to be indexed and inserted to search_vector field")))
This code generates this error:
FieldError: Cannot resolve expression type, unknown output_field
It seemed to be a bug since I found similar usages in forums..
Change History (16)
comment:1 Changed 2 years ago by
Summary: | SerachVectorField cannot be updated pure string → SerachVectorField cannot be updated with pure string |
---|
comment:2 Changed 2 years ago by
Summary: | SerachVectorField cannot be updated with pure string → Automatically resolve Value's output_field for stdlib types. |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:3 Changed 2 years ago by
Owner: | changed from nobody to Simon Charette |
---|---|
Status: | new → assigned |
comment:4 Changed 2 years ago by
Has patch: | set |
---|
comment:5 Changed 2 years ago by
Patch needs improvement: | set |
---|
comment:6 Changed 19 months ago by
Cc: | Matt Westcott added |
---|
In case it hasn't already been noted - the example above did previously work in 2.2, and the error is a regression in 2.2.1, specifically this commit: https://github.com/django/django/commit/88bf635c356b4d3a47e88dc4142b90060ce3c2ef . As such, I think this might justify being upgraded to a bug.
(FWIW, we encountered this independently here: https://github.com/wagtail/wagtail/issues/5547)
comment:7 Changed 11 months ago by
Patch needs improvement: | unset |
---|
comment:9 Changed 10 months ago by
Cc: | Sergey Fedoseev added |
---|
comment:10 Changed 10 months ago by
Patch needs improvement: | set |
---|
comment:11 Changed 9 months ago by
Patch needs improvement: | unset |
---|
comment:13 Changed 9 months ago by
Triage Stage: | Accepted → Ready for checkin |
---|---|
Version: | 2.2 → master |
Specifying an explicit
output_field
forValue
should resolve your issue.I guess
Value._resolve_output_field
could be made smarter for some stdlib types such asstr
,float
,int
,Decimal
,date
,datetime
so I'm tentatively accepting on this basis.