#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)
follow-up: 2 comment:1 by , 5 years ago
| Resolution: | → needsinfo |
|---|---|
| Status: | new → closed |
comment:2 by , 5 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
Also, if I have more than two connection configurations with different NAME, this code will try to process only one next configuration, and if it is incorrect, it will throw an exception without trying to check the next connection.
comment:3 by , 5 years ago
| Component: | contrib.postgres → Database layer (models, ORM) |
|---|---|
| Resolution: | needsinfo |
| Status: | closed → new |
I've also seen this with django_cockroachdb (which inherits the PostgreSQL backend).
comment:4 by , 5 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 3.2 → 3.1 |
Seems like a regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe which is also part of 3.1.
comment:5 by , 5 years ago
| Severity: | Normal → Release blocker |
|---|
Thanks for details, I can confirm that it's a regression in f48f671223a20b161ca819cf7d6298e43b8ba5fe.
comment:6 by , 5 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:8 by , 5 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Thanks for the report, however the builtin
django.db.backends.postgresqlbackend (on Python3.9.0+and3.8.5) raisesConnection refusedfor 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?