Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32403 closed Bug (fixed)

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

Reported by: Kazantcev Andrey Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 3.1
Severity: Release blocker Keywords: postgres db
Cc: 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

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.

Change History (11)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: needsinfo
Status: newclosed

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?

in reply to:  1 comment:2 by Kazantcev Andrey, 4 years ago

Replying to Mariusz Felisiak:

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', '{}'))
    }
}

No specific database env vars sets. Used only default values.

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

Version 2, edited 4 years ago by Kazantcev Andrey (previous) (next) (diff)

comment:3 by Tim Graham, 4 years ago

Component: contrib.postgresDatabase layer (models, ORM)
Resolution: needsinfo
Status: closednew

I've also seen this with django_cockroachdb (which inherits the PostgreSQL backend).

comment:4 by Simon Charette, 4 years ago

Triage Stage: UnreviewedAccepted
Version: 3.23.1

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

comment:5 by Mariusz Felisiak, 4 years ago

Severity: NormalRelease blocker

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

comment:6 by Mariusz Felisiak, 4 years ago

Owner: set to Mariusz Felisiak
Status: newassigned

comment:7 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:8 by Carlton Gibson, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In f131841c:

Fixed #32403 -- Fixed re-raising DatabaseErrors when using only 'postgres' database.

Thanks Kazantcev Andrey for the report.

Regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 7d658893:

[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

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 9efe832e:

[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

Note: See TracTickets for help on using tickets.
Back to Top