Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPTIONS key type for DBConfig is potentially incorrect #218

Closed
kezabelle opened this issue Jun 2, 2023 · 1 comment · Fixed by #232
Closed

OPTIONS key type for DBConfig is potentially incorrect #218

kezabelle opened this issue Jun 2, 2023 · 1 comment · Fixed by #232

Comments

@kezabelle
Copy link

kezabelle commented Jun 2, 2023

2.0.0 introduces DBConfig as a TypedDict, specified as:

class DBConfig(TypedDict, total=False):
...
    OPTIONS: Optional[Dict[str, Any]]

As far as I can tell from a cursory reading of parse, it cannot be Optional (None) - options is always at least an empty directory ({}), but it can be NotRequired as a key (which is AFAIK already handled by the class being total=False) because if it is empty it just won't be set.

This came up for me because I have some code which does:

if "OPTIONS" in parsed_db_config:
    parsed_db_config["OPTIONS"].update(...some_stuff)

which gets raised as an error:

error: Item "None" of "Optional[Dict[str, Any]]" has no attribute "update"  [union-attr]

Here's the totality of options being used and then potentially bound to the OPTIONS key:

options: Dict[str, Any] = {}
for key, values in query.items():
if spliturl.scheme == "mysql" and key == "ssl-ca":
options["ssl"] = {"ca": values[-1]}
continue
options[key] = values[-1]
if ssl_require:
options["sslmode"] = "require"
# Support for Postgres Schema URLs
if "currentSchema" in options and engine in (
"django.contrib.gis.db.backends.postgis",
"django.db.backends.postgresql_psycopg2",
"django.db.backends.postgresql",
"django_redshift_backend",
"timescale.db.backends.postgresql",
"timescale.db.backends.postgis",
):
options["options"] = "-c search_path={0}".format(options.pop("currentSchema"))
if options:
parsed_config["OPTIONS"] = options

palfrey added a commit to palfrey/dj-database-url that referenced this issue Nov 8, 2023
@palfrey
Copy link
Member

palfrey commented Nov 8, 2023

#232 will fix this

@palfrey palfrey linked a pull request Nov 8, 2023 that will close this issue
palfrey added a commit to palfrey/dj-database-url that referenced this issue Dec 9, 2023
palfrey added a commit that referenced this issue Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants