Skip to content

fix: replace print() with logger.warning() in extensions catalog warnings - #3969

Open
Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/extensions-use-logger
Open

Quratulain-bilal wants to merge 2 commits into
github:mainfrom
Quratulain-bilal:fix/extensions-use-logger

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

print(..., file=sys.stderr) is inappropriate for library code - it bypasses the logging framework and can't be silenced or redirected by consumers.

Fix

Replaced with logger.warning() for proper log management. Removed unused local sys imports.

…ings

Print statements to stderr are not appropriate for library code that may
be consumed by tools or tests. Replaced with logger.warning() for proper
log management. Removed unused local sys imports.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces direct stderr warnings with standard Python logging in the extension catalog.

Changes:

  • Added a module logger.
  • Migrated two catalog warnings to logger.warning().
  • Removed unused local sys imports.
Show a summary per file
File Description
src/specify_cli/extensions/__init__.py Routes catalog warnings through logging.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (1)

src/specify_cli/extensions/init.py:3757

  • Please cover the partial-fetch failure path with caplog: make one catalog raise ExtensionError, let another succeed, and assert the named warning is logged while merging continues. This is the second logging behavior changed by the PR and currently has no regression test.
                logger.warning(
                    "Could not fetch catalog '%s': %s", catalog_entry.name, e,
                )
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +3520 to 3523
logger.warning(
"Using non-default extension catalog. "
"Only use catalogs from sources you trust.",
file=sys.stderr,
)
Verify that when _fetch_single_catalog raises ExtensionError, the error
is logged at WARNING level with the catalog name and error message,
instead of being printed to stderr or silently swallowed.
@mnriem mnriem added triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate author-needs-disclosure AI use, or the agent/model/settings behind it, not disclosed per CONTRIBUTING author-awaiting Waiting on author response labels Sep 9, 2026
@mnriem
mnriem requested a balanced review from Copilot September 9, 2026 12:14
@mnriem

mnriem commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks — this is the right fix (stderr print in library code can't be silenced/redirected by consumers), and the caplog regression test is exactly what I want to see. Just one thing before review: please disclose any AI assistance per CONTRIBUTING. With that added, this is in good shape — and for reference, PRs like this one (focused + a real test) are much easier to prioritize than the untested atomic-write batch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unused import will fail Ruff CI, and one changed warning path lacks logging coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

src/specify_cli/extensions/init.py:3522

  • The PR changes this security warning from direct stderr output to logging, but the existing environment-variable test only checks the returned catalog entry. Add a caplog assertion for this path so a regression back to print() (or removal of the warning) is covered as well.
                    logger.warning(
                        "Using non-default extension catalog. "
                        "Only use catalogs from sources you trust.",
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread tests/test_extensions.py
"""When a catalog fetch fails, the error must be logged at WARNING
level instead of being silently swallowed or printed to stderr."""
import logging
from pathlib import Path
@Quratulain-bilal

Copy link
Copy Markdown
Contributor Author

AI Assistance Disclosure

I used AI assistance (GitHub Copilot) to identify print() calls in library code that bypass the logging framework. The refactoring was reviewed and validated by me — I verified the logger output matches the original stderr behavior and added a regression test using caplog to confirm warnings are logged at the correct level.

@mnriem I've added the AI disclosure above. This PR was developed with Copilot assistance to identify the print-to-logger migration points, and I personally reviewed the changes and wrote the caplog regression test. Ready for re-review when you have a chance.

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

@mnriem mnriem removed author-needs-disclosure AI use, or the agent/model/settings behind it, not disclosed per CONTRIBUTING author-awaiting Waiting on author response labels Sep 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants