#34486: SearchVector.as_sql causes AttributeError
----------------------------------+--------------------------------------
     Reporter:  Scott Macpherson  |                    Owner:  (none)
         Type:  Bug               |                   Status:  closed
    Component:  contrib.postgres  |                  Version:  4.2
     Severity:  Normal            |               Resolution:  duplicate
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------

Comment (by Scott Macpherson):

 The trouble doesn't seem to be with the structure of the call to
 `compose_sql`, but it's called on a `DatabaseOperations` object with a
 `DatabaseWrapper` that doesn't have a connection. When `mogrify` retrieves
 that connection it gets a NoneType back.

 I can't work out why the tests in `SearchHeadlineTests` don't capture this
 - could it have something to do with the way connections are reused in the
 tests, but not for a cold request?

 {{{
 …
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/django/contrib/postgres/search.py", line 320, in as_sql
     ", ".join(
     ^
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/django/contrib/postgres/search.py", line 321, in <genexpr>
     connection.ops.compose_sql(f"{option}=%s", [value])
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/django/db/backends/postgresql/operations.py", line 205, in
 compose_sql
     return mogrify(sql, params, self.connection)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/django/db/backends/postgresql/psycopg_any.py", line 21, in
 mogrify
     return ClientCursor(connection.connection).mogrify(sql, params)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/psycopg/cursor.py", line 672, in __init__
     super().__init__(connection)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/Users/scott/Development/python_venvs/zerosleeps/lib/python3.11
 /site-packages/psycopg/cursor.py", line 65, in __init__
     self._pgconn = connection.pgconn
                    ^^^^^^^^^^^^^^^^^

 Exception Type: AttributeError at /search/
 Exception Value: 'NoneType' object has no attribute 'pgconn'
 }}}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018774650302-e86edb2e-0788-454e-b9ac-0151c951f7cb-000000%40eu-central-1.amazonses.com.

Reply via email to