Привет, столкнулся с странной ошибкой.
Модели:
class Accounts(Base):
__tablename__ = 'accounts'
id = Column(Integer, autoincrement=True, primary_key=True)
name = Column(String, unique=True)
number = Column(String(30), unique=True)
class Groups(Base):
__tablename__ = 'groups'
id = Column(Integer, autoincrement=True, primary_key=True)
join_name = Column(String)
spam_time_interval = Column(Integer) # minutes
message_text = Column(String)
class WorkerTask(Base):
__tablename__ = 'workers'
id = Column(Integer, autoincrement=True, primary_key=True)
group_id = Column(Integer, ForeignKey('groups.id'))
group = relationship("Groups", backref=backref("groups", uselist=False))
account_id = Column(Integer, ForeignKey('accounts.id'))
account = relationship("Accounts", backref=backref("account", uselist=False))
Селект:
async def get_group_workers_db(group_id):
stmt = select(WorkerTask.id, WorkerTask.account.number).where(WorkerTask.group_id == group_id)
return engine.connect().execute(stmt).fetchall()
Ошибка:
Traceback (most recent call last):
File "D:\Да это же мой код\Aiogram\GroupMultiSpamer\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 327, in __getattr__
return getattr(self.comparator, key)
AttributeError: 'Comparator' object has no attribute 'number'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Да это же мой код\Aiogram\GroupMultiSpamer\tes.py", line 6, in <module>
asyncio.run(get_group_workers_db(1))
File "C:\Program Files\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "D:\Да это же мой код\Aiogram\GroupMultiSpamer\database\responses.py", line 92, in get_group_workers_db
stmt = select(WorkerTask.id, WorkerTask.account.number).where(WorkerTask.group_id == group_id)
File "D:\Да это же мой код\Aiogram\GroupMultiSpamer\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 329, in __getattr__
util.raise_(
File "D:\Да это же мой код\Aiogram\GroupMultiSpamer\venv\lib\site-packages\sqlalchemy\util\compat.py", line 210, in raise_
raise exception
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with WorkerTask.account has an attribute 'number'
В чём может быть причина?