Exception on /console/api/apps/543f2eb1-e384-4e54-825f-71aecfdf80ca/site [POST] #8805

Closed
opened 2026-02-21 18:27:46 -05:00 by yindo · 2 comments
Owner

Originally created by @gaspire on GitHub (Mar 1, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

修改应用配置报错:
Exception on /console/api/apps/543f2eb1-e384-4e54-825f-71aecfdf80ca/site [POST]

Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @gaspire on GitHub (Mar 1, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 修改应用配置报错: Exception on /console/api/apps/543f2eb1-e384-4e54-825f-71aecfdf80ca/site [POST] <img width="1591" alt="Image" src="https://github.com/user-attachments/assets/1f425489-80c9-456c-9dba-cd3ae8a46bcd" /> ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:27:46 -05:00
yindo closed this issue 2026-02-21 18:27:46 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 1, 2025):

The error "instance of a SQLAlchemy model is not bound to a session" during a POST request can occur if the SQLAlchemy session is not properly managing the model instance. In your case, ensure that the site object is added to the session before committing any changes. Here's a solution to address this issue:

with Session(db.engine) as session:
    site = session.query(Site).filter(Site.app_id == app_model.id).first()

    if not site:
        raise NotFound

    for attr_name in [
        "title",
        "icon_type",
        "icon",
        "icon_background",
        "description",
        "default_language",
        "chat_color_theme",
        "chat_color_theme_inverted",
        "customize_domain",
        "copyright",
        "privacy_policy",
        "custom_disclaimer",
        "customize_token_strategy",
        "prompt_public",
        "show_workflow_steps",
        "use_icon_as_answer_icon",
    ]:
        value = args.get(attr_name)
        if value is not None:
            setattr(site, attr_name, value)

    site.updated_by = current_user.id
    site.updated_at = datetime.now(UTC).replace(tzinfo=None)
    
    # Add the site object to the session
    session.add(site)
    session.commit()

By adding session.add(site), you ensure that the site object is part of the session, which should resolve the error [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 1, 2025): <!-- Answer --> The error "instance of a SQLAlchemy model is not bound to a session" during a POST request can occur if the SQLAlchemy session is not properly managing the model instance. In your case, ensure that the `site` object is added to the session before committing any changes. Here's a solution to address this issue: ```python with Session(db.engine) as session: site = session.query(Site).filter(Site.app_id == app_model.id).first() if not site: raise NotFound for attr_name in [ "title", "icon_type", "icon", "icon_background", "description", "default_language", "chat_color_theme", "chat_color_theme_inverted", "customize_domain", "copyright", "privacy_policy", "custom_disclaimer", "customize_token_strategy", "prompt_public", "show_workflow_steps", "use_icon_as_answer_icon", ]: value = args.get(attr_name) if value is not None: setattr(site, attr_name, value) site.updated_by = current_user.id site.updated_at = datetime.now(UTC).replace(tzinfo=None) # Add the site object to the session session.add(site) session.commit() ``` By adding `session.add(site)`, you ensure that the `site` object is part of the session, which should resolve the error <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/controllers/console/app/site.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e42e89d1-30c2-4d86-89a9-69c47dc3c758?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 1, 2025):

Duplicated https://github.com/langgenius/dify/issues/14583

@crazywoola commented on GitHub (Mar 1, 2025): Duplicated https://github.com/langgenius/dify/issues/14583
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8805