Files
langflow/docs/docs
Eric Hare 4dc9e28eb0 fix(initial_setup): upsert by (user_id, name) when loading flows from disk (#13132)
* fix(initial_setup): upsert by (user_id, name) when loading flows from disk

Langflow fails to start with IntegrityError on the unique_flow_name
constraint when LANGFLOW_LOAD_FLOWS_PATH is used in CI/CD pipelines and
the flow file's id differs from the DB record's id (e.g. nightly
upgrade, regenerated UUIDs, fresh DB). Manual DB intervention was the
only workaround.

Root cause: find_existing_flow only looked up by endpoint_name and id,
never by (user_id, name). The unique constraint is on (user_id, name),
so when those lookups missed, the loader fell through to INSERT and
PostgreSQL rejected it.

Fix:
- find_existing_flow now takes optional keyword args (user_id, name)
  and falls back to a (user_id, name) lookup when endpoint_name/id
  don't match. The endpoint_name branch is also scoped by user_id when
  supplied so it can't accidentally return another user's flow.
- upsert_flow_from_file passes name and user_id to find_existing_flow.
  When the match is by name (existing.id != file's flow_id), the DB id
  is preserved during the setattr loop -- rewriting it from under FK
  referrers was unsafe and was never required by the original logic.

Tests: 8 regression tests cover lookup precedence (id wins, endpoint
scoped by user, name fallback fires only when id misses), the
reporter's scenario (no IntegrityError on repeated import with
differing file ids), DB-id preservation on name-match, and a
no-regression case where matched-by-id behavior is unchanged.

Fixes the CI/CD upgrade failure reported in IBM Cloud Slack
(C06SUKEN3LJ thread 1777992833.170099).

* fix(initial_setup): fix matched_by_id on SQLite, improve update log message

Normalize existing.id to UUID before the matched_by_id comparison.
On SQLite, SQLAlchemy can return ids as strings; str == UUID is always
False, so matched_by_id would silently be wrong and the file id would
be dropped even on a genuine id-match.

Improve the update log to include the DB id and flow name alongside the
file's UUID so the CI/CD upgrade scenario (name-matched upsert with
differing UUIDs) is debuggable from logs.

* [autofix.ci] apply automated fixes

* fix: Preserve db id

* [autofix.ci] apply automated fixes

* feat: Add flag to control name matching overwrite

* [autofix.ci] apply automated fixes

* Flip the default value for the flag

* Update test_upsert_flow_from_file.py

* fix: Sqlalchemy-based crash on startup

---------

Co-authored-by: Jordan Frazier <jordan.frazier@datastax.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-05-16 01:20:14 +00:00
..
2026-05-11 14:40:02 +00:00