I am creating a system where users can subscribe to one-another. This is my current code:
from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.sql.schema import Column, ForeignKey from sqlalchemy.sql.sqltypes import BigInteger, String, Integer, TIMESTAMP Base = declarative_base() engine = None session = None class User(Base): __tablename__ = 'users' id = Column(BigInteger, primary_key=True) email = Column(String(100), nullable=False) displayname = Column(String(255), nullable=False) password = Column(String(80), nullable=False) uhash = Column(String(80), nullable=False) verified = Column(Integer, nullable=False) registerdate = Column(TIMESTAMP, nullable=True) def __init__(self, email, password, displayname, uhash, verified, registerdate): self.email = email self.password = password self.displayname = displayname self.uhash = uhash self.verified = verified self.registerdate = registerdate def __repr__(self): return "User(%s, %s, %s, %s)" % (self.email, self.password, self.displayname, self.verified) class Video(Base): __tablename__ = 'videos' id = Column(BigInteger, primary_key=True) name = Column(String(255)) def __init__(self, name): self.name = name class UserSubscription(Base): __tablename__ = 'usersubscriptions' id = Column(BigInteger, primary_key=True) subscriber_id = Column("subscriber_id", BigInteger, ForeignKey("users.id")) subscriber = relationship("User", backref="subsciptions", primaryjoin=(User.id == subscriber_id)) subscribed_id = Column("subscribed_id", BigInteger, ForeignKey("users.id")) subscribed = relationship("User", backref="subscribers", primaryjoin=(User.id == subscribed_id)) def __init__(self, subscriber, subscribed): self.subscriber = subscriber self.subscribed = subscribed def setup_mysqldb(uri): engine = create_engine(uri) session = sessionmaker() session.configure(bind=engine) Base.metadata.create_all(engine) return session() Whenever I start up my Flask server (that uses this), it produces this error: Traceback (most recent call last): File "/home/midnightas/.p2/pool/plugins/org.python.pydev_5.1.2.201606231256/pysrc/_pydevd_bundle/pydevd_reload.py", line 345, in _update if oldobj != newobj and str(oldobj) != str(newobj) and repr(oldobj) != repr(newobj): File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/operators.py", line 310, in __ne__ return self.operate(ne, other) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/attributes.py", line 175, in operate return op(self.comparator, *other, **kwargs) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1333, in __ne__ return _orm_annotate(self.__negated_contains_or_equals(other)) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1245, in __negated_contains_or_equals state = attributes.instance_state(other) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/attributes.py", line 193, in __getattr__ key) AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with UserSubscription.subscribed has an attribute '_sa_instance_state' What did I do wrong in UserSubscription? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.