Skip to content

[Cosmos] Fix new pylint errors#46459

Draft
tvaron3 wants to merge 1 commit intoAzure:mainfrom
tvaron3:fix/cosmos-pylint-errors
Draft

[Cosmos] Fix new pylint errors#46459
tvaron3 wants to merge 1 commit intoAzure:mainfrom
tvaron3:fix/cosmos-pylint-errors

Conversation

@tvaron3
Copy link
Copy Markdown
Member

@tvaron3 tvaron3 commented Apr 22, 2026

Summary

The Build Analyze (pylint) job for sdk/cosmos/azure-cosmos was failing with 9 new pylint errors introduced by recent commits (between 2025-08 and 2026-04). All flagged production code is in azure/cosmos/. This PR applies minimal, surgical fixes — no behavioural changes, no test edits.

Errors fixed (by category)

Code Rule Files
C4766 do-not-log-exceptions-if-not-debug _read_items_helper.py, _cosmos_http_logging_policy.py (×2), _global_endpoint_manager.py, _query_advisor/_query_advice.py, _routing/routing_map_provider.py, _routing/aio/routing_map_provider.py, aio/_global_endpoint_manager_async.py
C4762 do-not-log-raised-errors _routing/routing_map_provider.py, _routing/aio/routing_map_provider.py

Fix strategy (one line per category)

  • Re-raised exceptions in routing_map_provider.py (sync + async) — removed the try/except CosmosHttpResponseError: log; raise block around _ReadPartitionKeyRanges. The exception now propagates unchanged to the caller (which is responsible for logging). This also fixes the resulting W0706 try-except-raise and removes a now-unused CosmosHttpResponseError import.
  • Background task failures in _global_endpoint_manager{,_async}.py — lowered the swallowed background-thread exception log from error(..., exc_info=True) to debug(..., exc_info=True). Foreground request flow is unaffected; debug logging still preserves diagnostics.
  • Re-raising error path in _read_items_helper.py — lowered the parallel-execute exception log to debug (the exception is re-raised on the next line, so callers can log the full detail).
  • Optional response-header parse failure in _query_advice.py — lowered to debug (the function returns None on failure and the caller treats advice as optional).
  • _cosmos_http_logging_policy.py — the existing # pylint: disable=do-not-log-exceptions-if-not-debug suppression was on the wrong physical line (the trailing argument line) so pylint did not honour it. Moved the suppression to the line pylint actually reports (the logger.warning(...) call). No behavioural change.

Disable comments

Per the task constraints, no new # pylint: disable=... comments were added. The only adjustments to pylint suppressions are repositioning the two existing do-not-log-exceptions-if-not-debug disables in _cosmos_http_logging_policy.py onto the line pylint actually flags.

Validation

cd sdk/cosmos/azure-cosmos

# Standard pylint env (CI: tox -e pylint)
pylint --rcfile=../../../pylintrc      --output-format=parseable azure/cosmos
# → 10.00/10

# next-pylint env (CI: tox -e next-pylint, source side)
pylint --rcfile=../../../eng/pylintrc  --output-format=parseable azure/cosmos
# → 10.00/10

# Import sanity
python -c "import azure.cosmos; import azure.cosmos.aio"
# → ok

Both pylint configurations report 10.00/10 after the fix; baseline main reports 9.99/10 with 9 errors (the ones fixed here). Tests under tests/ were intentionally not modified — pre-existing test/sample warnings (e.g. wrong-import-order, broad-exception-caught, no-name-in-module) are unrelated to this PR's scope and are only checked by the optional next-pylint job's tests/samples sub-runs.

Out of scope / not changed

  • tests/ — only checked by next-pylint --next=True (optional/weekly), not by the standard Build Analyze job. Pre-existing issues left untouched.
  • samples/ — same as above.
  • No changes to public API, no behavioural changes, no test additions (this is a lint-only maintenance fix).

…ise)

The azure-pylint-guidelines-checker (v0.5.7) and pylint (v4.0.4) used by the
Azure SDK Build Analyze pipeline started flagging recently-introduced code in
azure-cosmos with the following error categories:

  - C4766 do-not-log-exceptions-if-not-debug
  - C4762 do-not-log-raised-errors

Fixes (production source under azure/cosmos/ only):

  * _read_items_helper.py: Lower the exception log in the parallel-execute
    error path to DEBUG (the exception is re-raised; callers log details).
  * _cosmos_http_logging_policy.py: Move the existing
    'pylint: disable=do-not-log-exceptions-if-not-debug' suppression onto the
    line pylint actually reports (the logger.warning call) for the two
    failed-to-log fallback handlers. No behavioural change.
  * _global_endpoint_manager.py / aio/_global_endpoint_manager_async.py:
    Background health-check task failures now log at DEBUG (with exc_info)
    instead of ERROR. The exception is intentionally swallowed so background
    failures cannot affect foreground request flow; debug-level logging
    still preserves diagnostics.
  * _query_advisor/_query_advice.py: Lower the response-header parse-failure
    log to DEBUG; the function returns None on failure and the caller treats
    advice as optional, so a warning is not warranted.
  * _routing/routing_map_provider.py and _routing/aio/routing_map_provider.py:
    Drop the try/except-raise block around _ReadPartitionKeyRanges that only
    logged-and-re-raised. The CosmosHttpResponseError now propagates unchanged
    to the caller (documented via inline comment + existing :raises: docstring
    in the async variant). Removes both C4762 and the resulting W0706
    (try-except-raise) and the now-unused CosmosHttpResponseError import.

Validation:
  cd sdk/cosmos/azure-cosmos
  pylint --rcfile=../../../pylintrc      azure/cosmos   # 10.00/10
  pylint --rcfile=../../../eng/pylintrc  azure/cosmos   # 10.00/10
  python -c 'import azure.cosmos'                       # ok

No '# pylint: disable=...' was added that did not already exist in the
surrounding code; the only disable adjustments are repositioning existing
suppressions onto the line pylint actually flags.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant