motional / nuplan-devkit

The devkit of the nuPlan dataset.
https://www.nuplan.org
Other
662 stars 126 forks source link

Fix incomaptability with sqlalchemy==1.4.27 #327

Open Akamel01 opened 1 year ago

Akamel01 commented 1 year ago

Describe the bug

sqlalchemy.exc.ArgumentError: Type annotation for "Scene.goal_ego_pose" can't be correctly interpreted for Annotated Declarative Table form. ORM annotations should normally make use of the Mapped[] generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[]. To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "allow_unmapped = True" on the class or a superclass this class. (Background on this error at: https://sqlalche.me/e/20/zlpr)

Setup

Ubuntu on linux machine

Stack Trace

Traceback (most recent call last): File "/snap/pycharm-community/332/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode coro = func() File "", line 1, in File "/snap/pycharm-community/332/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, kwargs) File "/home/akamel/nuplan-devkit/nuplan/database/nuplan_db_orm/nuplandb.py", line 13, in from nuplan.database.nuplan_db_orm.image import Image File "/snap/pycharm-community/332/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, *kwargs) File "/home/akamel/nuplan-devkit/nuplan/database/nuplan_db_orm/image.py", line 22, in from nuplan.database.nuplan_db_orm.lidar_pc import LidarPc File "/snap/pycharm-community/332/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, kwargs) File "/home/akamel/nuplan-devkit/nuplan/database/nuplan_db_orm/lidar_pc.py", line 21, in from nuplan.database.nuplan_db_orm.scene import Scene File "/snap/pycharm-community/332/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/home/akamel/nuplan-devkit/nuplan/database/nuplan_db_orm/scene.py", line 19, in class Scene(Base): File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py", line 193, in init ) File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 248, in _as_declarative cls = self.cls File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 329, in setup_mapping if _get_immediate_cls_attr(self.cls, "declare_last"): File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 566, in init

on a superclass that is mapped, then

File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 1011, in _scan_attributes

we can't write it because field.metadata is immutable :( so we have

File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 1285, in _collect_annotation File "/home/akamel/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/util.py", line 2365, in _extract_mapped_subtype sqlalchemy.exc.ArgumentError: Type annotation for "Scene.goal_ego_pose" can't be correctly interpreted for Annotated Declarative Table form. ORM annotations should normally make use of the Mapped[] generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[]. To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "allow_unmapped = True" on the class or a superclass this class. (Background on this error at: https://sqlalche.me/e/20/zlpr)

The solution:

this line __allow_unmapped = True should be added before the line tablename__ ='xxxx'

in the following files (scene.py, scenario_tag.py. track.py, TrafficLightStatus.py)