Created
August 9, 2013 16:07
-
-
Save sivy/6194866 to your computer and use it in GitHub Desktop.
Test case for error described in http://www.monkinetic.com/2013/08/07/sqlalchemy-property-exists-on-mapper. IN this case, the error does not occur.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
sys.path.append(os.path.abspath('.')) | |
sys.path.append(os.path.abspath('markbox')) | |
print sys.path | |
# from markbox.models import UserBlogSettings | |
from sqlalchemy import create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker, scoped_session, relationship | |
import sqlalchemy as sa | |
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:" | |
engine = create_engine(SQLALCHEMY_DATABASE_URI, echo='debug') | |
db_session_maker = scoped_session(sessionmaker(autocommit=False, | |
autoflush=False, | |
bind=engine)) | |
session = db_session_maker() | |
Base = declarative_base() | |
Base.query = db_session_maker.query_property() | |
class UserBlogSettings(Base): | |
__tablename__ = 'user_blogsettings' | |
id = sa.Column(sa.Integer, primary_key=True) | |
uid = sa.Column(sa.String(256)) | |
# blog title | |
# returns a query => blog.sync_stats.all() | |
sync_stats = relationship('SyncStats', backref='blog') | |
class SyncStats(Base): | |
""" | |
Store various statistics about sync operations | |
""" | |
__tablename__ = 'system_syncstats' | |
id = sa.Column(sa.Integer, primary_key=True) | |
uid = sa.Column(sa.String(256), sa.ForeignKey('user_blogsettings.uid')) | |
def main(): | |
Base.metadata.create_all(engine) | |
q = UserBlogSettings.query.limit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment