Skip to content

Commit 25f4697

Browse files
bennyhsiaobennyhsiao
authored andcommitted
fix: remove the default value and extend the engine options with passing value
1 parent 3e4111b commit 25f4697

1 file changed

Lines changed: 7 additions & 22 deletions

File tree

celery/backends/database/__init__.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
InvalidRequestError,
3131
StaleDataError,
3232
)
33-
DEFAULT_DATABASE_ENGINE_OPTIONS = {
34-
'pool_pre_ping': True,
35-
'pool_recycle': 3600,
36-
}
3733

3834

3935
@contextmanager
@@ -93,24 +89,13 @@ def __init__(self, dburi=None, engine_options=None, url=None, **kwargs):
9389

9490
self.url = url or dburi or conf.database_url
9591

96-
# Start with the default engine options, but allow explicit empty dicts
97-
# from configuration or constructor arguments to disable all defaults.
98-
engine_options_base = dict(DEFAULT_DATABASE_ENGINE_OPTIONS)
99-
100-
conf_engine_options = conf.database_engine_options
101-
if conf_engine_options is not None:
102-
if not conf_engine_options:
103-
engine_options_base = {}
104-
else:
105-
engine_options_base.update(conf_engine_options)
106-
107-
if engine_options is not None:
108-
if not engine_options:
109-
engine_options_base = {}
110-
else:
111-
engine_options_base.update(engine_options)
112-
113-
self.engine_options = engine_options_base
92+
# Merge engine options: defaults from config <- constructor overrides
93+
# The defaults (pool_pre_ping=True, pool_recycle=3600) are defined in
94+
# celery/app/defaults.py under database_engine_options
95+
self.engine_options = dict(
96+
conf.database_engine_options or {},
97+
**(engine_options or {})
98+
)
11499
self.short_lived_sessions = kwargs.get(
115100
'short_lived_sessions',
116101
conf.database_short_lived_sessions)

0 commit comments

Comments
 (0)