Skip to content

Resolve "Reorganize datamodel files"

Description

This MR introduces several code changes primarily associated with the migration to SQLAlchemy 2.0. The following is a (non-comprehensive) overview of these changes:

  • Fix proper typing using Mapped type annotations.
  • A lot can be derived directly from these Mapped type annotations, allowing for the removal of: related classes and uselist in relationship(), the nullable parameter in mapped_column(), as well as SQL types without arguments (e.g., Integer).
  • Replace Optional[type] with type | None. For Mapped type annotations of relationship(), this can be accomplished by importing annotations from the __future__ module. This postponed evaluation of annotations also avoids the need for type annotations as string literals.
  • Replace legacy use of backref with explicit relationship() constructs using back_populates.
  • Some minor bug fixes following the proper type annotation of attachment and broadcast modules.
  • Index constructs are moved to __table_args__ for clarity (with two notable exceptions in the workflow module).
  • Removal of mapped_column() directives without any parameters. An important exception are columns that later are used in composite foreign key or index constructs, which throws a NameError if the empty mapped_column() is removed (possible bug?).

Many of these SQLAlchemy-related style choices should preferably be picked up by mypy. I will be working on implementing some relevant checks in the ella_mypy plugin.

Notes to review (code/docs/QA)

Related issues

Closes #2242 (closed)

Edited by Vetle Simensen

Merge request reports