SQLAlchemy Transaction error #721

Closed
opened 2026-02-21 17:28:10 -05:00 by yindo · 3 comments
Owner

Originally created by @waltcow on GitHub (Nov 21, 2023).

Dify version

0.3.21

Cloud or Self Hosted

Self Hosted

Steps to reproduce

psycopg2.InterfaceError: cursor already closed

        with db.engine.begin() as conn:
            rs = conn.execute(db.text(sql_query), arg_dict)

        response_data = []

        for i in rs:
            response_data.append({
                'date': str(i.date),
                'interactions': float(i.interactions.quantize(Decimal('0.01')))
            })

        return jsonify({
            'data': response_data
        })

(https://github.com/langgenius/dify/blob/cc35d0645a862c7eea28ff34b044ba8ebf29ff6e/api/controllers/console/app/statistic.py#L259C1-L272C11)

image

✔️ Expected Behavior

no error

Actual Behavior

sql error

Originally created by @waltcow on GitHub (Nov 21, 2023). ### Dify version 0.3.21 ### Cloud or Self Hosted Self Hosted ### Steps to reproduce > psycopg2.InterfaceError: cursor already closed ```python with db.engine.begin() as conn: rs = conn.execute(db.text(sql_query), arg_dict) response_data = [] for i in rs: response_data.append({ 'date': str(i.date), 'interactions': float(i.interactions.quantize(Decimal('0.01'))) }) return jsonify({ 'data': response_data }) ``` (https://github.com/langgenius/dify/blob/cc35d0645a862c7eea28ff34b044ba8ebf29ff6e/api/controllers/console/app/statistic.py#L259C1-L272C11) <img width="2421" alt="image" src="https://github.com/langgenius/dify/assets/3941174/4851b484-5896-4a9d-ac38-845fa377d25f"> ### ✔️ Expected Behavior no error ### ❌ Actual Behavior sql error
yindo added the 🐞 bug label 2026-02-21 17:28:10 -05:00
yindo closed this issue 2026-02-21 17:28:10 -05:00
Author
Owner

@takatost commented on GitHub (Nov 21, 2023):

Can you please make a PR if possible? I would be extremely grateful!

@takatost commented on GitHub (Nov 21, 2023): Can you please make a PR if possible? I would be extremely grateful!
Author
Owner

@waltcow commented on GitHub (Nov 21, 2023):

Okay

@waltcow commented on GitHub (Nov 21, 2023): Okay
Author
Owner

@waltcow commented on GitHub (Nov 21, 2023):

Can you please make a PR if possible? I would be extremely grateful!

https://github.com/langgenius/dify/pull/1586

@waltcow commented on GitHub (Nov 21, 2023): > Can you please make a PR if possible? I would be extremely grateful! https://github.com/langgenius/dify/pull/1586
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#721