Skip to content

Commit

Permalink
Restore id column definition to five classes
Browse files Browse the repository at this point in the history
I haven't been able to find a quick solution to the mypy/ruff problems
caused by classes referring to the inherited id field in relationship()
defintions (foreign_keys and remote_side). Having redundant id column
definitions in 5 classes  seems to be the simplest solution and a
reasonable trade-off (we had them in 166 classes).
  • Loading branch information
jdavcs committed Jan 17, 2025
1 parent a45a5fc commit 8889d8e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5772,6 +5772,7 @@ class LibraryFolder(Base, Dictifiable, HasName, Serializable):
__tablename__ = "library_folder"
__table_args__ = (Index("ix_library_folder_name", "name", mysql_length=200),)

id: Mapped[int] = mapped_column(primary_key=True)
parent_id: Mapped[Optional[int]] = mapped_column(ForeignKey("library_folder.id"), index=True)
create_time: Mapped[datetime] = mapped_column(default=now, nullable=True)
update_time: Mapped[datetime] = mapped_column(default=now, onupdate=now, nullable=True)
Expand All @@ -5788,9 +5789,7 @@ class LibraryFolder(Base, Dictifiable, HasName, Serializable):
order_by=asc(name),
back_populates="parent",
)
parent: Mapped[Optional["LibraryFolder"]] = relationship(
back_populates="folders", remote_side=["id"] # type:ignore[list-item]
)
parent: Mapped[Optional["LibraryFolder"]] = relationship(back_populates="folders", remote_side=[id])

active_folders: Mapped[List["LibraryFolder"]] = relationship(
primaryjoin=("and_(LibraryFolder.parent_id == LibraryFolder.id, not_(LibraryFolder.deleted))"),
Expand Down Expand Up @@ -5910,6 +5909,7 @@ def parent_library(self):
class LibraryDataset(Base, Serializable):
__tablename__ = "library_dataset"

id: Mapped[int] = mapped_column(primary_key=True)
# current version of dataset, if null, there is not a current version selected
library_dataset_dataset_association_id: Mapped[Optional[int]] = mapped_column(
ForeignKey(
Expand All @@ -5933,7 +5933,7 @@ class LibraryDataset(Base, Serializable):
"LibraryDatasetDatasetAssociation", foreign_keys=library_dataset_dataset_association_id, post_update=True
)
expired_datasets: Mapped[List["LibraryDatasetDatasetAssociation"]] = relationship(
foreign_keys=["id", library_dataset_dataset_association_id], # type:ignore[list-item]
foreign_keys=[id, library_dataset_dataset_association_id],
primaryjoin=(
"and_(LibraryDataset.id == LibraryDatasetDatasetAssociation.library_dataset_id, \
not_(LibraryDataset.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.id))"
Expand Down Expand Up @@ -6917,6 +6917,7 @@ class HistoryDatasetCollectionAssociation(

__tablename__ = "history_dataset_collection_association"

id: Mapped[int] = mapped_column(primary_key=True)
collection_id: Mapped[Optional[int]] = mapped_column(ForeignKey("dataset_collection.id"), index=True)
history_id: Mapped[Optional[int]] = mapped_column(ForeignKey("history.id"), index=True)
name: Mapped[Optional[str]] = mapped_column(TrimmedString(255))
Expand All @@ -6940,7 +6941,7 @@ class HistoryDatasetCollectionAssociation(
copied_from_history_dataset_collection_association = relationship(
"HistoryDatasetCollectionAssociation",
primaryjoin=copied_from_history_dataset_collection_association_id == id,
remote_side=["id"], # type:ignore[list-item]
remote_side=[id],
uselist=False,
)
implicit_input_collections: Mapped[List["ImplicitlyCreatedDatasetCollectionInput"]] = relationship(
Expand Down Expand Up @@ -8462,6 +8463,7 @@ class WorkflowComment(Base, RepresentById):

__tablename__ = "workflow_comment"

id: Mapped[int] = mapped_column(primary_key=True)
order_index: Mapped[Optional[int]]
workflow_id: Mapped[int] = mapped_column(ForeignKey("workflow.id"), index=True)
position: Mapped[Optional[bytes]] = mapped_column(MutableJSONType)
Expand All @@ -8485,7 +8487,7 @@ class WorkflowComment(Base, RepresentById):
parent_comment: Mapped[Optional["WorkflowComment"]] = relationship(
primaryjoin=(lambda: WorkflowComment.id == WorkflowComment.parent_comment_id),
back_populates="child_comments",
remote_side=["id"], # type:ignore[list-item]
remote_side=[id],
)

child_comments: Mapped[List["WorkflowComment"]] = relationship(
Expand Down Expand Up @@ -10591,13 +10593,12 @@ class Tag(Base, RepresentById):
__tablename__ = "tag"
__table_args__ = (UniqueConstraint("name"),)

id: Mapped[int] = mapped_column(primary_key=True)
type: Mapped[Optional[int]]
parent_id: Mapped[Optional[int]] = mapped_column(ForeignKey("tag.id"))
name: Mapped[Optional[str]] = mapped_column(TrimmedString(255))
children: Mapped[List["Tag"]] = relationship(back_populates="parent")
parent: Mapped[Optional["Tag"]] = relationship(
back_populates="children", remote_side=["id"] # type:ignore[list-item]
)
parent: Mapped[Optional["Tag"]] = relationship(back_populates="children", remote_side=[id])

def __str__(self):
return f"Tag(id={self.id}, type={self.type or -1}, parent_id={self.parent_id}, name={self.name})"
Expand Down

0 comments on commit 8889d8e

Please sign in to comment.