Skip to content

Code cleanup - #950

Merged
chrismaddalena merged 16 commits into
masterfrom
hotfix/code-cleanup
Jul 28, 2026
Merged

Code cleanup#950
chrismaddalena merged 16 commits into
masterfrom
hotfix/code-cleanup

Conversation

@chrismaddalena

Copy link
Copy Markdown
Collaborator

Continuing code quality clean up.

Copilot AI review requested due to automatic review settings July 27, 2026 21:29
@augmentcode

augmentcode Bot commented Jul 27, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR continues a code-quality cleanup pass across Ghostwriter.

Changes:

  • Replaces broad/implicit exception handling with explicit exception classes (e.g., Exception, json.JSONDecodeError, typed tuples in migrations).
  • Adds logger.debug(...) statements in several previously-silent except blocks to improve diagnosability.
  • Marks Severity.get_default_weight() as a @staticmethod to reflect its usage.
  • Removes unused variables and unused test locals to reduce noise and satisfy linting.
  • Makes minor test assertion cleanups for clarity (e.g., assertNotIn, assertEqual).

Technical Notes: The intent appears to be tightening error handling while keeping runtime behavior the same, with additional debug-level observability where exceptions were previously swallowed.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

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

This PR continues code-quality cleanup across Ghostwriter’s Django backend by tightening exception handling, replacing silent pass blocks with debug logging, and simplifying tests/assertions for clarity.

Changes:

  • Replaced bare except: clauses with explicit exception types (e.g., Exception, ValueError, TypeError) in tests, migrations, and runtime code paths.
  • Replaced several silent exception pass blocks with logger.debug(...) to preserve observability without changing user-facing behavior.
  • Minor test cleanups (assertion simplifications, removing unused variables/comments).

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ghostwriter/shepherd/tests/test_models.py Narrows bare except to except Exception in model URL tests.
ghostwriter/shepherd/tasks.py Replaces silent exception handling with debug logging for missing history / non-JSON API responses.
ghostwriter/shepherd/migrations/0037_convert_dns_record_to_json.py Narrows migration exception handling to explicit exception types.
ghostwriter/rolodex/views.py Adds debug logging when a URL kwarg is not numeric instead of silently ignoring.
ghostwriter/rolodex/tests/test_models.py Narrows bare except to except Exception in model URL tests.
ghostwriter/reporting/views2/report.py Logs WebSocket send failures (gaierror) instead of silently ignoring.
ghostwriter/reporting/views2/report_observation_link.py Logs WebSocket send failures (gaierror) instead of silently ignoring.
ghostwriter/reporting/views2/report_finding_link.py Logs WebSocket send failures (gaierror) instead of silently ignoring.
ghostwriter/reporting/tests/test_views.py Simplifies assertions and removes unused locals in tests.
ghostwriter/reporting/tests/test_rich_text_docx.py Removes commented-out manual inspection code in tests.
ghostwriter/reporting/tests/test_models.py Narrows bare except to except Exception and simplifies assertions/unused locals.
ghostwriter/reporting/models.py Refactors default-weight helper and adds debug logging for missing prior DB entry.
ghostwriter/reporting/migrations/0026_convert_linting_status_to_json.py Narrows migration exception handling to explicit exception types.
ghostwriter/oplog/views.py Replaces silent exception handling with debug logging during export/zip operations.
ghostwriter/oplog/tests/test_forms.py Removes an unused local in a form test.
ghostwriter/modules/reportwriter/richtext/ooxml.py Logs invalid font-size style values instead of silently ignoring.
ghostwriter/modules/reportwriter/richtext/docx.py Logs missing DOCX styles instead of silently ignoring; removes unused locals.
ghostwriter/modules/health_utils.py Narrows bare except to except Exception in cache health checks.
ghostwriter/modules/custom_serializers.py Adds debug logging for a caught KeyError; introduces multiple trivial __init__ overrides.
ghostwriter/modules/cloud_monitors.py Removes redundant ignore_tags initialization in S3 fetcher.
ghostwriter/home/templatetags/custom_tags.py Adds logging and logs parse failures instead of silently ignoring.
ghostwriter/api/views.py Uses json.JSONDecodeError consistently (removing separate import) and logs missing recording replacement case.
Comments suppressed due to low confidence (6)

ghostwriter/modules/custom_serializers.py:311

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:352

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:579

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:672

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:781

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:806

  • This init override only calls super().__init__ and adds no behavior. It increases noise and may trigger linter warnings (e.g., useless-super-delegation). Remove it unless you plan to add initialization logic.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

Comment thread ghostwriter/reporting/models.py Outdated
Comment thread ghostwriter/modules/custom_serializers.py
Copilot AI review requested due to automatic review settings July 27, 2026 21:33

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

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (6)

ghostwriter/modules/custom_serializers.py:288

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:352

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:579

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:672

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:781

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

ghostwriter/modules/custom_serializers.py:806

  • This __init__ override only delegates to super() and does not change serializer behavior. It adds noise and makes future diffs harder to read; consider removing it.
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

Comment thread ghostwriter/shepherd/migrations/0037_convert_dns_record_to_json.py Outdated
Comment thread ghostwriter/modules/custom_serializers.py
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.64602% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.18%. Comparing base (562d756) to head (f0c5098).

Files with missing lines Patch % Lines
ghostwriter/reporting/tests/test_models.py 37.50% 5 Missing ⚠️
ghostwriter/shepherd/tests/test_models.py 0.00% 4 Missing ⚠️
ghostwriter/reporting/tests/test_exporters.py 97.33% 2 Missing ⚠️
ghostwriter/rolodex/tests/test_models.py 0.00% 2 Missing ⚠️
ghostwriter/shepherd/tasks.py 0.00% 2 Missing ⚠️
ghostwriter/home/templatetags/custom_tags.py 66.66% 1 Missing ⚠️
ghostwriter/oplog/views.py 50.00% 1 Missing ⚠️
.../migrations/0026_convert_linting_status_to_json.py 0.00% 1 Missing ⚠️
ghostwriter/reporting/views2/report.py 0.00% 1 Missing ⚠️
...hostwriter/reporting/views2/report_finding_link.py 0.00% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
+ Coverage   92.16%   92.18%   +0.01%     
==========================================
  Files         442      443       +1     
  Lines       33796    33872      +76     
==========================================
+ Hits        31149    31224      +75     
- Misses       2647     2648       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 27, 2026 21:48

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

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 27, 2026 22:05

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

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.

Comment on lines 285 to 290
type_or_template_id = self.kwargs["type_or_template_id"]
try:
type_or_template_id = int(type_or_template_id)
except ValueError:
pass
logger.debug("Report type or template ID is not numeric: %s", type_or_template_id)

Comment on lines 2 to 6
from datetime import datetime
import io
from typing import Any, Iterable
from typing import Any, Callable, Iterable
import re
from venv import logger
@chrismaddalena
chrismaddalena merged commit 8a18e3b into master Jul 28, 2026
11 of 12 checks passed
@chrismaddalena
chrismaddalena deleted the hotfix/code-cleanup branch July 28, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants