Skip to content

Commit 8b5730e

Browse files
committed
mm_cfg circular import issue
1 parent 19b6e5b commit 8b5730e

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

Mailman/Queue/IncomingRunner.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,39 +143,46 @@ def _get_pipeline(self, mlist, msg, msgdata):
143143
if pipeline is None:
144144
pipeline = getattr(mlist, 'pipeline', None)
145145
if pipeline is None:
146-
syslog('debug', 'mm_cfg module file: %s', mm_cfg.__file__)
147-
syslog('debug', 'Loading GLOBAL_PIPELINE from mm_cfg: %s (type: %s)', mm_cfg.GLOBAL_PIPELINE, type(mm_cfg.GLOBAL_PIPELINE).__name__)
146+
# Store the original mm_cfg reference to avoid circular imports
147+
original_mm_cfg = mm_cfg
148+
149+
syslog('debug', 'mm_cfg module file: %s', original_mm_cfg.__file__)
150+
syslog('debug', 'Loading GLOBAL_PIPELINE from mm_cfg: %s (type: %s)', original_mm_cfg.GLOBAL_PIPELINE, type(original_mm_cfg.GLOBAL_PIPELINE).__name__)
148151
syslog('debug', 'sys.path at pipeline load: %s', sys.path)
149-
syslog('debug', 'mm_cfg module loaded at: %s', mm_cfg.__cached__ if hasattr(mm_cfg, '__cached__') else 'No cache')
150-
syslog('debug', 'mm_cfg module name: %s', mm_cfg.__name__)
151-
syslog('debug', 'mm_cfg module spec: %s', mm_cfg.__spec__)
152+
syslog('debug', 'mm_cfg module loaded at: %s', original_mm_cfg.__cached__ if hasattr(original_mm_cfg, '__cached__') else 'No cache')
153+
syslog('debug', 'mm_cfg module name: %s', original_mm_cfg.__name__)
154+
syslog('debug', 'mm_cfg module spec: %s', original_mm_cfg.__spec__)
155+
syslog('debug', 'mm_cfg module id: %s', id(original_mm_cfg))
156+
syslog('debug', 'mm_cfg module dict: %s', list(original_mm_cfg.__dict__.keys())[:10])
152157
# Check if there's a site-specific override
153-
if hasattr(mm_cfg, '__file__'):
154-
mm_cfg_dir = os.path.dirname(mm_cfg.__file__)
158+
if hasattr(original_mm_cfg, '__file__'):
159+
mm_cfg_dir = os.path.dirname(original_mm_cfg.__file__)
155160
site_config = os.path.join(mm_cfg_dir, 'mm_cfg.py')
156161
if os.path.exists(site_config):
157162
syslog('debug', 'Site config exists: %s', site_config)
158163

159164
# Force reload mm_cfg if GLOBAL_PIPELINE is not available
160-
if not hasattr(mm_cfg, 'GLOBAL_PIPELINE'):
165+
if not hasattr(original_mm_cfg, 'GLOBAL_PIPELINE'):
161166
syslog('debug', 'GLOBAL_PIPELINE not found, forcing reload of mm_cfg')
162167
import importlib
163-
importlib.reload(mm_cfg)
164-
syslog('debug', 'After reload - GLOBAL_PIPELINE: %s', getattr(mm_cfg, 'GLOBAL_PIPELINE', 'NOT FOUND'))
168+
importlib.reload(original_mm_cfg)
169+
syslog('debug', 'After reload - GLOBAL_PIPELINE: %s', getattr(original_mm_cfg, 'GLOBAL_PIPELINE', 'NOT FOUND'))
165170

166-
pipeline = mm_cfg.GLOBAL_PIPELINE
171+
pipeline = original_mm_cfg.GLOBAL_PIPELINE
167172

168173
# Ensure pipeline is a list that can be sliced
169174
if not isinstance(pipeline, list):
170175
import traceback
176+
# Use the original mm_cfg reference to avoid circular imports
177+
original_mm_cfg = mm_cfg
171178
syslog('error', 'GLOBAL_PIPELINE is not a list: %s (type: %s)',
172179
pipeline, type(pipeline).__name__)
173-
syslog('error', 'mm_cfg module file: %s', mm_cfg.__file__)
180+
syslog('error', 'mm_cfg module file: %s', original_mm_cfg.__file__)
174181
syslog('error', 'sys.path: %s', sys.path)
175-
syslog('error', 'mm_cfg.__dict__ keys: %s', list(mm_cfg.__dict__.keys())[:10])
176-
syslog('error', 'mm_cfg module loaded at: %s', mm_cfg.__cached__ if hasattr(mm_cfg, '__cached__') else 'No cache')
177-
syslog('error', 'mm_cfg module name: %s', mm_cfg.__name__)
178-
syslog('error', 'mm_cfg module spec: %s', mm_cfg.__spec__)
182+
syslog('error', 'mm_cfg.__dict__ keys: %s', list(original_mm_cfg.__dict__.keys())[:10])
183+
syslog('error', 'mm_cfg module loaded at: %s', original_mm_cfg.__cached__ if hasattr(original_mm_cfg, '__cached__') else 'No cache')
184+
syslog('error', 'mm_cfg module name: %s', original_mm_cfg.__name__)
185+
syslog('error', 'mm_cfg module spec: %s', original_mm_cfg.__spec__)
179186
syslog('error', 'Traceback: %s', ''.join(traceback.format_stack()))
180187
# Fallback to a basic pipeline
181188
pipeline = ['SpamDetect', 'Approve', 'Moderate', 'Hold',

0 commit comments

Comments
 (0)