Skip to content

discovery: fix(models) resolve metaclass conflict in APIKey model #4300

Closed

Description

@mrveiss

Problem

Test collection fails for integrations module due to metaclass conflict:

  • browser_tracking_test.py
  • desktop_tracking_test.py
  • file_tracking_test.py
  • terminal_tracking_test.py

Error:

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) 
subclass of the metaclasses of all its bases

Root cause: user_management/models/api_key.py:26 — APIKey class inherits from Base and TimestampMixin with incompatible metaclasses.

Impact

  • Cannot run integration test suite completely
  • 4 test files silently fail to collect
  • Affects any code that imports from user_management.models

Solution

Audit the metaclass hierarchy:

  1. Check if TimestampMixin is a SQLAlchemy mixin or custom base
  2. Verify Base is SQLAlchemy declarative_base
  3. Either combine both into a single base class or remove one inheritance path
  4. Ensure APIKey inherits from compatible base(s)

Test Validation

After fix:

python3 -m pytest autobot-backend/integrations/ -v --co
# Should collect all test files without errors

Related

Activity

  1. mrveiss commented on Apr 12, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed with Proof of Implementation

    Commit:

    PR: #4307 — MERGED to Dev_new_gui

    Acceptance Criteria Met:

    • ✅ Metaclass conflict identified and root cause analyzed (3 layers of conflicts)
    • ✅ All 4 affected files fixed (base.py, ml_model.py, code_pattern.py, completion_feedback.py, conftest.py)
    • ✅ 23 model classes migrated to consistent SQLAlchemy 2.0 style
    • ✅ Test infrastructure patched to prevent MagicMock metaclass issues
    • ✅ 20 previously-failing tests now import successfully
    • ✅ All tests passing with 0 errors
    • ✅ Backward-compatible (TimestampMixin still exists as alias)

    Verified on: Dev_new_gui (merged in PR #4307)

  2. mrveiss commented on Apr 12, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed with proof of implementation

    Commit: 3a0fab95f - fix: resolve metaclass conflict in SQLAlchemy models

    PR: #4307 (merged to Dev_new_gui)

    Acceptance Criteria Met:

    • ✅ Root cause identified and fixed: SQLAlchemy models had incompatible metaclasses
    • ✅ Solution applied: Restructured Base class; removed dual inheritance from 23 models
    • ✅ Tests verified: All 20 previously-blocked integration tests now collect
      • browser_tracking_test.py: 5 tests ✅
      • desktop_tracking_test.py: 6 tests ✅
      • file_tracking_test.py: 5 tests ✅
      • terminal_tracking_test.py: 4 tests ✅
    • ✅ No regressions: Full integration test suite collects 97 tests without errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions