[Django] #32403: When run test with off postgres database got `RuntimeError: generator didn't yield` instead of connection error

130 views
Skip to first unread message

Django

unread,
Feb 1, 2021, 7:47:49 AM2/1/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
--------------------------------------------+-----------------------------
Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 3.2
Severity: Normal | Keywords: postgres db
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+-----------------------------
I have only default database configuration and if I run tests without
started postgresql I got
{{{
File "C:\Users\Asus\.virtualenvs\curds-cxXQlVO3\lib\site-
packages\django\test\runner.py", line 695, in run_tests
old_config = self.setup_databases(aliases=databases)
File "C:\Users\Asus\.virtualenvs\curds-cxXQlVO3\lib\site-
packages\django\test\runner.py", line 614, in setup_databases
return _setup_databases(
File "C:\Users\Asus\.virtualenvs\curds-cxXQlVO3\lib\site-
packages\django\test\utils.py", line 170, in setup_databases
connection.creation.create_test_db(
File "C:\Users\Asus\.virtualenvs\curds-cxXQlVO3\lib\site-
packages\django\db\backends\base\creation.py", line 55, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "C:\Users\Asus\.virtualenvs\curds-cxXQlVO3\lib\site-
packages\django\db\backends\base\creation.py", line 186, in
_create_test_db
with self._nodb_cursor() as cursor:
File "c:\python39\lib\contextlib.py", line 119, in __enter__
raise RuntimeError("generator didn't yield") from None
RuntimeError: generator didn't yield
}}}

Seams `_nodb_cursor` method didn't do yield when handling error.

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

Django

unread,
Feb 1, 2021, 3:33:24 PM2/1/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
----------------------------------+--------------------------------------

Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version: 3.2
Severity: Normal | Resolution: needsinfo

Keywords: postgres db | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => needsinfo


Comment:

Thanks for the report, however the builtin `django.db.backends.postgresql`
backend (on Python `3.9.0+` and `3.8.5`) raises `Connection refused` for
me (as expected):
{{{
django.db.utils.OperationalError: could not connect to server: Connection
refused
Is the server running on host "localhost" (127.0.0.1) and
accepting
TCP/IP connections on port 5432?
}}}

Can you share more details or a database configuration?

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

Django

unread,
Feb 1, 2021, 3:57:33 PM2/1/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
----------------------------------+--------------------------------------

Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version: 3.2
Severity: Normal | Resolution: needsinfo

Keywords: postgres db | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Kazantcev Andrey):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for the report, however the builtin
`django.db.backends.postgresql` backend (on Python `3.9.0+` and `3.8.5`)
raises `Connection refused` for me (as expected):
> {{{
> django.db.utils.OperationalError: could not connect to server:
Connection refused
> Is the server running on host "localhost" (127.0.0.1) and
accepting
> TCP/IP connections on port 5432?
> }}}
>
> Can you share more details or a database configuration?

Configuration
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('POSTGRESQL_NAME', 'postgres'),
'USER': os.getenv('POSTGRESQL_USER', 'postgres'),
'PASSWORD': os.getenv('POSTGRESQL_PASSWORD', 'postgres'),
'HOST': os.getenv('POSTGRESQL_HOST', 'localhost'),
'PORT': os.getenv('POSTGRESQL_PORT', '5432'),
'OPTIONS': json.loads(os.getenv('POSTGRESQL_ENGINE_OPTIONS',
'{}'))
}
}
```

I found a problem. The problem is in [these
lines](https://github.com/django/django/blob/f9cfd346f0222d86bfbac26ef5455806965bae6b/django/db/backends/postgresql/base.py#L324-L325).
If I have one connection and test expression in if return false then
function just return without reraise exception. And `contextmanager`
raises error `RuntimeError: generator didn't yield`

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

Django

unread,
Feb 1, 2021, 4:13:56 PM2/1/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------

Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:

Keywords: postgres db | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: closed => new
* resolution: needsinfo =>
* component: contrib.postgres => Database layer (models, ORM)


Comment:

I've [https://github.com/cockroachdb/django-cockroachdb/issues/182 also
seen this] with `django_cockroachdb` (which inherits the PostgreSQL
backend).

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

Django

unread,
Feb 1, 2021, 7:09:04 PM2/1/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------

Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 3.1

(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgres db | Triage Stage: Accepted

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

* version: 3.2 => 3.1
* stage: Unreviewed => Accepted


Comment:

Seems like a regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe which
is also part of 3.1.

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

Django

unread,
Feb 2, 2021, 4:34:27 AM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------

Reporter: Kazantcev Andrey | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres db | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* severity: Normal => Release blocker


Comment:

Thanks for details, I can confirm that it's a regression in
f48f671223a20b161ca819cf7d6298e43b8ba5fe.

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

Django

unread,
Feb 2, 2021, 4:34:43 AM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres db | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: (none) => Mariusz Felisiak
* status: new => assigned


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

Django

unread,
Feb 2, 2021, 7:28:10 AM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres db | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13963 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32403#comment:7>

Django

unread,
Feb 2, 2021, 10:51:28 AM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: postgres db | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Feb 2, 2021, 3:35:33 PM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: postgres db | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"f131841c601b9d4884adcdb284b4213c2ad89231" f131841c]:
{{{
#!CommitTicketReference repository=""
revision="f131841c601b9d4884adcdb284b4213c2ad89231"
Fixed #32403 -- Fixed re-raising DatabaseErrors when using only 'postgres'
database.

Thanks Kazantcev Andrey for the report.

Regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe.
}}}

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

Django

unread,
Feb 2, 2021, 3:36:11 PM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: postgres db | Triage Stage: Ready for
| 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:"7d658893450eb999f828c53a8e4efa03dff65cf3" 7d658893]:
{{{
#!CommitTicketReference repository=""
revision="7d658893450eb999f828c53a8e4efa03dff65cf3"
[3.2.x] Fixed #32403 -- Fixed re-raising DatabaseErrors when using only
'postgres' database.

Thanks Kazantcev Andrey for the report.

Regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe.
Backport of f131841c601b9d4884adcdb284b4213c2ad89231 from master
}}}

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

Django

unread,
Feb 2, 2021, 3:36:29 PM2/2/21
to django-...@googlegroups.com
#32403: When run test with off postgres database got `RuntimeError: generator
didn't yield` instead of connection error
-------------------------------------+-------------------------------------
Reporter: Kazantcev Andrey | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: postgres db | Triage Stage: Ready for
| 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:"9efe832ee1e5da326e4ee5ed370db963b8fe6624" 9efe832e]:
{{{
#!CommitTicketReference repository=""
revision="9efe832ee1e5da326e4ee5ed370db963b8fe6624"
[3.1.x] Fixed #32403 -- Fixed re-raising DatabaseErrors when using only
'postgres' database.

Thanks Kazantcev Andrey for the report.

Regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe.
Backport of f131841c601b9d4884adcdb284b4213c2ad89231 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages