Skip to content

refactor: fix flake8-django violations (DJ001/DJ008/DJ012). Closes #681#684

Merged
regulartim merged 3 commits intointelowlproject:developfrom
opbot-xd:refactor/fix-django-violations
Jan 6, 2026
Merged

refactor: fix flake8-django violations (DJ001/DJ008/DJ012). Closes #681#684
regulartim merged 3 commits intointelowlproject:developfrom
opbot-xd:refactor/fix-django-violations

Conversation

@opbot-xd
Copy link
Copy Markdown
Contributor

@opbot-xd opbot-xd commented Jan 6, 2026

Description

Fixes all remaining flake8-django violations and enables enforcement of DJ001, DJ008, and DJ012 rules.

Changes Overview

Phase 1: DJ008/DJ012 - Model str and Field Ordering

Phase 2: DJ001 - CharField null=True Violations

Model Changes:

  • FireHolList.source: Changed from null=True to blank=True, default=""
  • MassScanner.reason: Changed from null=True to blank=True, default=""

Logic Updates:
Updated get_firehol_categories() to filter empty source strings:

# Filter out empty strings from exact matches
firehol_categories.extend([source for source in exact_matches if source])

# Check entry.source is not empty before adding to network matches
if extracted_ip in network_range and entry.source and entry.source not in firehol_categories:

Why this matters: The maintainer requested that empty source values shouldn't pollute the firehol_categories list. This ensures that after migration from null=True to default='', the behavior remains correct.

Database Migration: Created migration 0026_fix_charfield_null_true.py to update schema.

Phase 3: Enable Enforcement

Related issues

Part of the Ruff migration series following #663, #671, #677 and #681. This is the final cleanup issue for Django-specific anti-patterns.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Checklist

  • I have read and understood the rules about how to Contribute to this project.
  • The pull request is for the branch develop.
  • I have added documentation of the new features.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • All the tests (old ones) gave 0 errors.
  • If changes were made to an existing model/serializer/view, the docs were updated and regenerated (check CONTRIBUTE.md).

- Add __str__ to UserProfile, Sensor, FireHolList, CowrieSession,
  Statistics, MassScanner, and WhatsMyIPDomain models
- Move UserProfile fields before Meta class (DJ012)
- Improves admin interface usability and debugging

Phase 1 of Django violations fix. All tests passing (282/282).
- Replace null=True with blank=True, default='' on FireHolList.source
  and MassScanner.reason fields
- Filter empty source strings in get_firehol_categories to prevent
  empty values in firehol_categories list
- Create database migration to update schema

Phase 2 of Django violations fix. All tests passing (282/282).
- Remove DJ001, DJ008, and DJ012 from ignore list
- All Django model violations have been fixed in previous commits
- Enforces Django best practices for CharField, __str__, and field ordering

Phase 3 (final) of Django violations fix. All tests passing (282/282).
All ruff checks passing.
@opbot-xd
Copy link
Copy Markdown
Contributor Author

opbot-xd commented Jan 6, 2026

hi @regulartim please review this PR when you get time.

@opbot-xd opbot-xd changed the title refactor: fix flake8-django violations (DJ001/DJ008/DJ012). Closes #678 refactor: fix flake8-django violations (DJ001/DJ008/DJ012). Closes #681 Jan 6, 2026
@opbot-xd
Copy link
Copy Markdown
Contributor Author

opbot-xd commented Jan 6, 2026

🎉 Ruff Migration Complete!

With this PR, the complete Ruff migration series is finished:

  1. Migrate from flake8/black/isort to Ruff #663 - Initial Ruff setup
  2. Refactor naming conventions to comply with PEP8 (N801/N802/N803/N806) #671 - PEP8 naming (N801/N802/N803/N806)
  3. Refactor code to comply with flake8-bugbear rules (B006/B008/B017/B023/B904) #677 - Bugbear violations (B006/B008/B017/B023/B904)
  4. Refactor code to comply with flake8-django rules (DJ001/DJ008/DJ012) #681 - Django violations (DJ001/DJ008/DJ012) ← This PR

Remaining Ignores in .ruff.toml - Rationale

8 rules remain ignored, all justified:

Functional/Compatibility (Can't Fix)

  • F403 - Wildcard imports in __init__.py for clean package API exposure
  • N804 - Django test framework uses self in classmethods by convention
  • N818 - Renaming legacy exceptions (e.g., ElasticServerDownException) would be breaking

Style Preferences (Don't Want to Fix)

  • C401/C408 - Project prefers explicit dict() for readability in complex scenarios
  • E501 - Docstrings need flexibility for URLs and examples
  • UP008 - Explicit super(ClassName, self) in tests improves debugging clarity
  • UP031 - Old-style % formatting acceptable in test strings

Copy link
Copy Markdown
Collaborator

@regulartim regulartim left a comment

Choose a reason for hiding this comment

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

Nice! 👍

@regulartim regulartim merged commit 6194db4 into intelowlproject:develop Jan 6, 2026
5 checks passed
@mlodic
Copy link
Copy Markdown
Member

mlodic commented Jan 6, 2026

great job @opbot-xd , thanks @regulartim for reviewing

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.

3 participants