14

I am using Flask for my app and getting AttributeError: '_Option' object has no attribute '_sa_instance_state' error. have no idea what it is about. I google it and it seems that it is a SQL-Alchemy issue. Could you please help me with that?

here is my models.py:

#current table is used to make navigation hierarchy. eg. menu/submenu
#eg. About Us (History, Mission, Vision)
menu_hierarchy = db.Table('menu_hierarchy',
        db.Column('parent_id', db.Integer, db.ForeignKey('menu.id')),
        db.Column('child_id', db.Integer, db.ForeignKey('menu.id'))
    )

class Menu(db.Model):
    """Menu is used for websites navigation titles.
    eg. Home/About Us/Blog/Contacts/and etc""" 

    id          = db.Column(db.Integer, primary_key = True)
    title       = db.Column(db.String(255))
    title_eng   = db.Column(db.String(255))
    alias       = db.Column(db.String(255))
    menu_type   = db.Column(db.String(10))
    ordering    = db.Column(db.SmallInteger, default = '1')
    check_out_time = db.Column(db.DateTime)
    access      = db.Column(db.String(30))
    published   = db.Column(db.SmallInteger, default = '1')
    parent_id   = db.relationship('Menu',
        secondary = menu_hierarchy,
        primaryjoin = (menu_hierarchy.c.parent_id == id),
        secondaryjoin = (menu_hierarchy.c.child_id == id),
        backref = db.backref('menu_hierarchy', lazy = 'dynamic'),
        lazy = 'dynamic')
    content     = db.Column(db.String)
    content_eng = db.Column(db.String)
    image       = db.Column(db.String(350))

2 Answers 2

14

It appears the problem is related to an integer (ID) being interpreted as an ORM object.

See this SO post which includes a relevant code sample.

Sign up to request clarification or add additional context in comments.

Comments

-1

Check if you deleted that field directly of Model instance. The principle is, that when you pass an object to a function, it is the same object and not a copy of it, so the deletion of an attribute by, for example, del vars(object)[field] would change the original object. Instead use copy.deepcopy(object) before changing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.