Question

when I try to flash message sqlalchemy.orm.exc.DetachedInstanceError appears and when I remove the bellow HTML code there is no any error, but the flashed message is displayed. Can anyone please help me with that??? :(

<div>
    {% with messages = get_flashed_messages() %}
    <ul>
        {% if messages %}
            {% for message in messages %}
                <li>{{ message }}</li>
            {% endfor %}
        {% endif %}
    </ul>
    {% endwith %}
</div>

the error:

sqlalchemy.orm.exc.DetachedInstanceError
DetachedInstanceError: Instance <User at 0x7f2f54fc8750> is not bound to a Session; attribute refresh operation cannot proceed
Was it helpful?

Solution

I tried to play around and I found my mistake. In fact there is no problem with HTML code. The problem was with my view code. Specifically, when I deleted a user I tried to flash deleted username and the flashed message I guess stacked, thus it gave me that error.

I am not sure about my point, but it worked for me. If you know the better solution please post your answer :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top