langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
33.3k stars 4.06k forks source link

fix: Problem in the "description" field when using MySQL #3678

Open xzqxnet0990 opened 2 months ago

xzqxnet0990 commented 2 months ago

Bug Description

I meet problem when using mysql, and doing the migration. I think the script should be changed at the beginning script "260dbcc8b680".

024-09-04 16:27:44,552 - migration.py[line:218] - INFO: Will assume non-transactional DDL. 2024-09-04 16:27:44,564 - migration.py[line:623] - INFO: Running upgrade -> 260dbcc8b680, Adds tables [09/04/24 16:27:44] ERROR 2024-09-04 16:27:44 - ERROR

utils utils.py:127
(pymysql.err.OperationalError)
(1170, "BLOB/TEXT column 'description'
used in key specification without a
key length")
[SQL: CREATE INDEX ix_flow_description
ON flow (description)]
(Background on this error at:
https://sqlalche.me/e/20/e3q8)
ERROR 2024-09-04 16:27:44 - ERROR - api_server.py:129
api_server -
(pymysql.err.OperationalError)
(1170, "BLOB/TEXT column
'description' used in key
specification without a key
length")
[SQL: CREATE INDEX
ix_flow_description ON flow
(description)]
(Background on this error at:
https://sqlalche.me/e/20/e3q8) 

Then I changed the scirpt and fix the problem. File: /base/langflow/alembic/versions/260dbcc8b680_adds_tables.py

line 103
with op.batch_alter_table("flow", schema=None) as batch_op:
    flow_columns = [col["name"] for col in inspector.get_columns("flow")]
    if "user_id" not in flow_columns:
        batch_op.add_column(
            sa.Column(
                "user_id",
                sqlmodel.sql.sqltypes.GUID(),
                nullable=True,  # This should be False, but we need to allow NULL values for now
            )
        )
    if "user.id" not in existing_fks_flow:
        batch_op.create_foreign_key("fk_flow_user_id", "user", ["user_id"], ["id"])
    if "ix_flow_description" not in existing_indices_flow:
        # Corrected way to specify key length for the description column index
        batch_op.create_index(batch_op.f("ix_flow_description"), [sa.text("description(255)")], unique=False)
    if "ix_flow_name" not in existing_indices_flow:
        batch_op.create_index(batch_op.f("ix_flow_name"), ["name"], unique=False)

Reproduction

using mysql to start server

Expected behavior

image

Who can help?

No response

Operating System

macs

Langflow Version

1.0.17

Python Version

3.12

Screenshot

No response

Flow File

No response

dosubot[bot] commented 2 months ago

To fix the issue with the "description" field in MySQL during migration in the script 260dbcc8b680, you need to specify a key length for the description column when creating the index. This is necessary because MySQL requires a length for indexing TEXT columns.

Here is the corrected part of the script:

with op.batch_alter_table("flow", schema=None) as batch_op:
    flow_columns = [col["name"] for col in inspector.get_columns("flow")]
    if "user_id" not in flow_columns:
        batch_op.add_column(
            sa.Column(
                "user_id",
                sqlmodel.sql.sqltypes.GUID(),
                nullable=True,  # This should be False, but we need to allow NULL values for now
            )
        )
    if "user.id" not in existing_fks_flow:
        batch_op.create_foreign_key("fk_flow_user_id", "user", ["user_id"], ["id"])
    if "ix_flow_description" not in existing_indices_flow:
        # Corrected way to specify key length for the description column index
        batch_op.create_index(batch_op.f("ix_flow_description"), [sa.text("description(255)")], unique=False)
    if "ix_flow_name" not in existing_indices_flow:
        batch_op.create_index(batch_op.f("ix_flow_name"), ["name"], unique=False)

This change ensures that the description column is indexed with a specified length, which is required by MySQL for TEXT columns [1].

To continue talking to Dosu, mention @dosu.

carlosrcoelho commented 2 months ago

@xzqxnet0990

Based on what you wrote here: https://github.com/langflow-ai/langflow/pull/3431

Are you going to create a PR for the fix?

xzqxnet0990 commented 2 months ago

@xzqxnet0990

Based on what you wrote here: #3431

Are you going to create a PR for the fix?

I already do it, see #3679

carlosrcoelho commented 1 month ago

@xzqxnet0990

I am just checking if you have any updates on #3679?