{{{
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:1>
* 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>
* owner: nobody => Simon Charette
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:3>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:5>
* 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>
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>
* cc: Sergey Fedoseev (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:9>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:10>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:11>
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>
* version: 2.2 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30446#comment:13>
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>
* 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>
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>
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>
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>
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>
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>