Skip to content

[CLEANUP][SONAR][LOW]: Redundant ternary - both branches identical in log_aggregator.py #2367

@crivetimihai

Description

@crivetimihai

Severity: LOW
File: mcpgateway/services/log_aggregator.py
Line: 873
Rule: python:S3923

Description

The conditional expression always evaluates to the same result regardless of the condition:

resolved_end = reference if window_end is None else reference

Both branches return reference, making the conditional useless.

Code Context

# Lines 863-883
if window_end is None:
    reference = datetime.now(timezone.utc)
else:
    reference = window_end.astimezone(timezone.utc)

reference = reference.replace(second=0, microsecond=0)
minutes_offset = reference.minute % self.aggregation_window_minutes
if window_end is None and minutes_offset:
    reference = reference - timedelta(minutes=minutes_offset)

resolved_end = reference if window_end is None else reference  # Redundant

Impact

None - code functions correctly. This is a maintainability/readability issue.

Suggested Fix

Replace the redundant ternary with a simple assignment:

resolved_end = reference

Metadata

Metadata

Assignees

Labels

COULDP3: Nice-to-have features with minimal impact if left out; included if time permitschoreLinting, formatting, dependency hygiene, or project maintenance choresgood first issueGood for newcomerspythonPython / backend development (FastAPI)sonarSonarQube code quality findings

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions