@@ -194,16 +194,19 @@ def psycopg_conn_string_from_settings_dict(settings_dict: dj_db_dict) -> str:
194194def combine_settings_dict (settings_dict1 : dj_db_dict , settings_dict2 : dj_db_dict , ** extra_options ) -> dj_db_dict :
195195 """Given two Django database settings dictionaries, combine them and return a new settings_dict"""
196196 settings_dict = deepcopy (settings_dict1 )
197- settings_dict ['OPTIONS' ] = deepcopy (settings_dict .get ('OPTIONS' , {}))
198-
199- # These extra options are used by AWX to set application_name
200- settings_dict ['OPTIONS' ].update (extra_options )
201197
202198 # Apply overrides specifically for the listener connection
203199 for k , v in settings_dict2 .items ():
204200 if k != 'OPTIONS' :
205201 settings_dict [k ] = v
206202
203+ # Merge the database OPTIONS
204+ # https://docs.djangoproject.com/en/5.2/ref/databases/#postgresql-connection-settings
205+ # These are not expected to be nested, as they are psycopg params
206+ settings_dict .setdefault ('OPTIONS' , {})
207+ # extra_options are used by AWX to set application_name, which is generally a good idea
208+ settings_dict ['OPTIONS' ].update (extra_options )
209+ # Apply overrides from nested OPTIONS for the listener connection
207210 for k , v in settings_dict2 .get ('OPTIONS' , {}).items ():
208211 settings_dict ['OPTIONS' ][k ] = v
209212
@@ -214,8 +217,9 @@ def get_pg_notify_params(alias: str = DEFAULT_DB_ALIAS, **extra_options) -> dict
214217 """Returns a dictionary that can be used as kwargs to create a psycopg.Connection
215218
216219 This should use the same connection parameters as Django does.
217- However, this also allows overrides specified by the setting
218- PG_NOTIFY_DATABASES and then the LISTENER_DATABASES, deprecated AWX setting.
220+ However, this also allows overrides specified by
221+ - PG_NOTIFY_DATABASES, higher precedence, preferred setting
222+ - LISTENER_DATABASES, lower precedence, deprecated AWX setting.
219223 """
220224 pg_notify_overrides = {}
221225 if hasattr (settings , 'PG_NOTIFY_DATABASES' ):
0 commit comments