[Django] #30446: SerachVectorField cannot be updated pure string

81 views
Skip to first unread message

Django

unread,
May 5, 2019, 7:25:04 PM5/5/19
to django-...@googlegroups.com
#30446: SerachVectorField cannot be updated pure string
-------------------------------------+-------------------------------------
Reporter: Ozan | Owner: nobody
Gerdaneri |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: SearchVector,
Severity: Normal | SearchVectorField , Value
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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..

--
Ticket URL: <https://code.djangoproject.com/ticket/30446>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 5, 2019, 7:25:42 PM5/5/19
to django-...@googlegroups.com
#30446: SerachVectorField cannot be updated with pure string
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage:
SearchVectorField , Value | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:1>

Django

unread,
May 5, 2019, 10:21:19 PM5/5/19
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.

-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Specifying an explicit `output_field` for `Value` should resolve your
issue.

{{{#!python
value = Value(
"a string to be indexed and inserted to search_vector field",
output_field=models.TextField(),
)
AModel.objects.filter(pk=1).update(
search_vector=SearchVector(value),
)
}}}

I guess `Value._resolve_output_field` could be made smarter for some
stdlib types such as `str`, `float`, `int`, `Decimal`, `date`, `datetime`
so I'm tentatively accepting on this basis.

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:2>

Django

unread,
May 12, 2019, 5:17:40 PM5/12/19
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* owner: nobody => Simon Charette
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:3>

Django

unread,
May 12, 2019, 5:30:05 PM5/12/19
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:4>

Django

unread,
May 12, 2019, 7:17:45 PM5/12/19
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:5>

Django

unread,
Sep 10, 2019, 2:39:48 PM9/10/19
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Westcott):

* cc: Matt Westcott (added)


Comment:

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)

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:6>

Django

unread,
Jun 16, 2020, 8:45:57 AM6/16/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"ea3beb4f5a61870c87ba028369de4d2c2f316ad0" ea3beb4]:
{{{
#!CommitTicketReference repository=""
revision="ea3beb4f5a61870c87ba028369de4d2c2f316ad0"
Refs #30446 -- Defined default output_field of text database functions.

This prevented the default behavior of
BaseExpression._resolve_output_field from error'ing out when such
functions accepted both expressions from mixed types
(e.g. SubStr(CharField, IntegerField, IntegerField)).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:8>

Django

unread,
Jun 29, 2020, 5:37:55 AM6/29/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sergey Fedoseev):

* cc: Sergey Fedoseev (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:9>

Django

unread,
Jul 1, 2020, 5:44:22 AM7/1/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:10>

Django

unread,
Jul 12, 2020, 1:31:19 AM7/12/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:11>

Django

unread,
Jul 14, 2020, 3:37:01 AM7/14/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Accepted
SearchVectorField , Value |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"1b7623fdfd8d4157b03126006f23f74f4ef6255c" 1b7623fd]:
{{{
#!CommitTicketReference repository=""
revision="1b7623fdfd8d4157b03126006f23f74f4ef6255c"
Refs #30446 -- Defined output_field of BoundingCircle() GIS database
function.

This prevented the default behavior of
BaseExpression._resolve_output_field from error'ing out when such
functions accepted both expressions from mixed types

(e.g. BoundingCircle(Polygon, num_seg=12)).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:12>

Django

unread,
Jul 15, 2020, 4:45:12 AM7/15/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* version: 2.2 => master
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:13>

Django

unread,
Jul 15, 2020, 5:29:35 AM7/15/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"156a2138db20abc89933121e4ff2ee2ce56a173a" 156a2138]:
{{{
#!CommitTicketReference repository=""
revision="156a2138db20abc89933121e4ff2ee2ce56a173a"
Refs #30446 -- Removed unnecessary Value(..., output_field) in docs and
tests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:15>

Django

unread,
Jul 15, 2020, 5:29:36 AM7/15/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1e38f1191de21b6e96736f58df57dfb851a28c1f" 1e38f11]:
{{{
#!CommitTicketReference repository=""
revision="1e38f1191de21b6e96736f58df57dfb851a28c1f"
Fixed #30446 -- Resolved Value.output_field for stdlib types.

This required implementing a limited form of dynamic dispatch to combine
expressions with numerical output. Refs #26355 should eventually provide
a better interface for that.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:14>

Django

unread,
Aug 31, 2020, 1:13:03 AM8/31/20
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"40894f29675b02be9597c3af358ed490d2b96651" 40894f2]:
{{{
#!CommitTicketReference repository=""
revision="40894f29675b02be9597c3af358ed490d2b96651"
Refs #30446 -- Added tests for resolving output_field of
CombinedExpression.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:16>

Django

unread,
Nov 8, 2023, 8:20:51 AM11/8/23
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"8b1acc0440418ac8f45ba48e2dfcf5126c83341b" 8b1acc04]:
{{{
#!CommitTicketReference repository=""
revision="8b1acc0440418ac8f45ba48e2dfcf5126c83341b"
Refs #30446, Refs #34944 -- Fixed crash when adding GeneratedField with
string Value().

This should allow smarter output_field inferring in functions dealing
with text expressions.

Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:17>

Django

unread,
Nov 8, 2023, 8:21:06 AM11/8/23
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"73869a51632b9f826d4d7b9e888f81d60b16e8b6" 73869a51]:
{{{
#!CommitTicketReference repository=""
revision="73869a51632b9f826d4d7b9e888f81d60b16e8b6"
[5.0.x] Refs #30446, Refs #34944 -- Fixed crash when adding GeneratedField
with string Value().

This should allow smarter output_field inferring in functions dealing
with text expressions.

Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.

Backport of 8b1acc0440418ac8f45ba48e2dfcf5126c83341b from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:18>

Django

unread,
Nov 14, 2023, 9:46:22 AM11/14/23
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"de4884b114534f43c49cf8c5b7f10181e737f4e9" de4884b1]:
{{{
#!CommitTicketReference repository=""
revision="de4884b114534f43c49cf8c5b7f10181e737f4e9"
Reverted "Refs #30446, Refs #34944 -- Fixed crash when adding
GeneratedField with string Value()."

This reverts commit 8b1acc0440418ac8f45ba48e2dfcf5126c83341b.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:19>

Django

unread,
Nov 14, 2023, 9:46:51 AM11/14/23
to django-...@googlegroups.com
#30446: Automatically resolve Value's output_field for stdlib types.
-------------------------------------+-------------------------------------
Reporter: Ozan Gerdaneri | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: SearchVector, | Triage Stage: Ready for
SearchVectorField , Value | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"5b1d0a6be06a14d130b2b7fa305dbc9e2a393761" 5b1d0a6]:
{{{
#!CommitTicketReference repository=""
revision="5b1d0a6be06a14d130b2b7fa305dbc9e2a393761"
[5.0.x] Reverted "Refs #30446, Refs #34944 -- Fixed crash when adding
GeneratedField with string Value()."

This reverts commit 8b1acc0440418ac8f45ba48e2dfcf5126c83341b.

Backport of de4884b114534f43c49cf8c5b7f10181e737f4e9 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:20>

Reply all
Reply to author
Forward
0 new messages