Skip to content

Refactor: Unify analysis and created_by_analysis fields in Relationship model #496

@JSv4

Description

@JSv4

Background

The Relationship model currently has two separate fields for tracking analysis relationships:

  • analysis (ForeignKey) - Organizational/filtering field (which mode relationship appears in)
  • created_by_analysis (ForeignKey) - Privacy/permissions field (who can see it)

This dual-field design mirrors the same architectural pattern found in the Annotation model (see #495), introducing the same complexity and potential security concerns.

Current State (Option 1 - Implemented)

We've implemented validation to enforce consistency between these fields as a temporary mitigation. See opencontractserver/annotations/models.py:275-305.

Additionally, relationships can now be private to extracts via created_by_extract field with mutual exclusivity enforced.

Proposed Solution (Option 2)

Remove the analysis field entirely and use only created_by_analysis for both purposes:

  • Simpler mental model
  • Reduced validation complexity
  • Better performance (one less field to index)
  • Clearer semantics
  • Consistency with Annotation model refactoring

Documentation

Full architectural analysis and migration strategy documented in:
docs/architecture/TODO_unify_relationship_analysis_fields.md

Related Work

Priority

Medium - This is a refactoring to improve architecture, not a critical bug.

Effort

Medium - Requires data migration, code updates across multiple files, and thorough testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions