Skip to content

Commit

Permalink
[orm] fixed sqlalchemy deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidprueser committed Feb 1, 2024
1 parent c9328d5 commit b03c6e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/pycram/orm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import getpass
import os
from dataclasses import field
from typing import Optional

import git
Expand All @@ -27,7 +28,7 @@ def get_pycram_version_from_git() -> Optional[str]:
return repo.head.object.hexsha


class _Base(DeclarativeBase):
class _Base(DeclarativeBase, MappedAsDataclass):
"""Dummy class"""
type_annotation_map = {
str: String(255)
Expand All @@ -41,7 +42,7 @@ def __tablename__(self):
return self.__name__


class Base(_Base, MappedAsDataclass):
class Base(_Base):
"""
Base class to add orm functionality to all pycram mappings
"""
Expand All @@ -59,7 +60,7 @@ def process_metadata(self):
tables"""


class MapperArgsMixin:
class MapperArgsMixin(MappedAsDataclass):
"""
MapperArgsMixin stores __mapper_args__ information for certain subclass-tables.
For information about Mixins, see https://docs.sqlalchemy.org/en/20/orm/declarative_mixins.html
Expand All @@ -72,14 +73,14 @@ def __mapper_args__(self):
return {"polymorphic_identity": self.__tablename__}


class PositionMixin:
class PositionMixin(MappedAsDataclass):
"""
PositionMixin holds a foreign key column and its relationship to the referenced table.
For information about Mixins, see https://docs.sqlalchemy.org/en/20/orm/declarative_mixins.html
"""

__abstract__ = True
position_to_init: bool = False
position_to_init: bool = field(default=False, init=False)

@declared_attr
def position_id(self) -> Mapped[int]:
Expand All @@ -90,14 +91,14 @@ def position(self):
return relationship(Position.__tablename__, init=False)


class QuaternionMixin:
class QuaternionMixin(MappedAsDataclass):
"""
QuaternionMixin holds a foreign key column and its relationship to the referenced table.
For information about Mixins, see https://docs.sqlalchemy.org/en/20/orm/declarative_mixins.html
"""

__abstract__ = True
orientation_to_init: bool = False
orientation_to_init: bool = field(default=False, init=False)

@declared_attr
def orientation_id(self) -> Mapped[int]:
Expand All @@ -108,14 +109,14 @@ def orientation(self):
return relationship(Quaternion.__tablename__, init=False)


class PoseMixin:
class PoseMixin(MappedAsDataclass):
"""
PoseMixin holds a foreign key column and its relationship to the referenced table.
For information about Mixins, see https://docs.sqlalchemy.org/en/20/orm/declarative_mixins.html
"""

__abstract__ = True
pose_to_init: bool = False
pose_to_init: bool = field(default=False, init=False)

@declared_attr
def pose_id(self) -> Mapped[int]:
Expand All @@ -126,7 +127,7 @@ def pose(self):
return relationship(Pose.__tablename__, init=False)


class ProcessMetaData(MappedAsDataclass, _Base):
class ProcessMetaData(_Base):
"""
ProcessMetaData stores information about the context of this experiment.
Expand Down
7 changes: 4 additions & 3 deletions src/pycram/orm/object_designator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from dataclasses import field
from typing import Optional

from pycram.orm.base import Base, MapperArgsMixin, PoseMixin, Pose
from sqlalchemy.orm import Mapped, mapped_column, declared_attr, relationship
from sqlalchemy.orm import Mapped, mapped_column, declared_attr, relationship, MappedAsDataclass
from sqlalchemy import ForeignKey
from ..enums import ObjectType


class ObjectMixin:
class ObjectMixin(MappedAsDataclass):
"""
ObjectMixin holds a foreign key column and its relationship to the referenced table.
For information about Mixins, see https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/mixins.html
"""

__abstract__ = True
object_to_init: bool = False
object_to_init: bool = field(default=False, init=False)

@declared_attr
def object_id(self) -> Mapped[int]:
Expand Down

0 comments on commit b03c6e2

Please sign in to comment.