AttributeError: 'int' object has no attribute '_sa_instance_state'

Solution 1:

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.