Whole file
joke2k/django-environ
The author described this change as “fix[db_url_config]: added postgres cluster DSN support (ie postgresql://username:password@host1:port1,host2:port2/database)”. It counts as a record because the check below fails on the code as it stood at 509cf7737 and passes on 0ca26c55c, with nothing else changed between the two runs.
Projectjoke2k/django-environ
Fix saved2021-12-09
Sharing licenceMIT · LICENSE.txt
Change size+19 −2
What the code was meant to do, written into the code itself as a save note
fix[db_url_config]: added postgres cluster DSN support (ie postgresql://username:password@host1:port1,host2:port2/database)
The change
| 12 | 12 | """ | |
| 13 | 13 | ||
| 14 | 14 | import ast | |
| 15 | + | import itertools | |
| 15 | 16 | import logging | |
| 16 | 17 | import os | |
| 17 | 18 | import re | |
| ⋯ | |||
| 501 | 502 | if url.port: | |
| 502 | 503 | path += ':{port}'.format(port=url.port) | |
| 503 | 504 | ||
| 505 | + | if url.scheme in cls.POSTGRES_FAMILY and ',' in url.netloc.rsplit('@', 1)[-1]: | |
| 506 | + | # Parsing postgres cluster dsn | |
| 507 | + | hostinfo = list( | |
| 508 | + | itertools.zip_longest( | |
| 509 | + | *( | |
| 510 | + | host.rsplit(':', 1) | |
| 511 | + | for host in url.netloc.rsplit('@', 1)[-1].split(',') | |
| 512 | + | ) | |
| 513 | + | ) | |
| 514 | + | ) | |
| 515 | + | hostname = ','.join(hostinfo[0]) | |
| 516 | + | port = ','.join(filter(None, hostinfo[1])) if len(hostinfo) == 2 else '' | |
| 517 | + | else: | |
| 518 | + | hostname = url.hostname | |
| 519 | + | port = url.port | |
| 520 | + | ||
| 504 | 521 | # Update with environment configuration. | |
| 505 | 522 | config.update({ | |
| 506 | 523 | 'NAME': path or '', | |
| 507 | 524 | 'USER': _cast_urlstr(url.username) or '', | |
| 508 | 525 | 'PASSWORD': _cast_urlstr(url.password) or '', | |
| 509 | - | 'HOST': url.hostname or '', | |
| 510 | - | 'PORT': _cast_int(url.port) or '', | |
| 526 | + | 'HOST': hostname or '', | |
| 527 | + | 'PORT': _cast_int(port) or '', | |
| 511 | 528 | }) | |
| 512 | 529 | ||
| 513 | 530 | if ( | |
The check that tells the two apart
fail→pass·tests/test_db.py::test_db_parsing[postgres_cluster]
Check file tests/test_db.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it509cf7737363a56e4464962dbae4ab72b801c7b3
Broken version dated2021-11-21
Moduleenviron.environ
Units changedEnv
Fingerprint9e84dd77fdeb0d78
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in joke2k/django-environ
- 2026-02-20Fix prometheus DB scheme aliases: underscores → hyphens (#585)
- 2026-02-17Feature/add choice parameter and raise an exception if fetched value is not within (#555)
- 2022-06-14Fix `environ.Path.__eq__()` to compare paths correctly
- 2021-12-13fix unquote vs unquote_plus issue
- 2021-09-01Fix db_url_config to work the same for all postgres-like schemes