AttributeError: ‘int’ object has no attribute ‘_sa_instance_state’

the problem is this:

post = Post(body=form.body.data,
            timestamp=datetime.utcnow(),
            thread=thread.id,
            author=g.user.id)

you want to work with ORM objects, not primary key columns:

post = Post(body=form.body.data,
            timestamp=datetime.utcnow(),
            thread=thread,
            author=g.user)

the error means that an integer is being interpreted as an ORM object.

Leave a Comment