From 02c6d77b649b1c399a40aa7008e6992bd31592b9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 23 Jun 2023 15:53:48 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20sort=20fields=20?= =?UTF-8?q?alphabetically=20before=20sorting=20by=20DIRECT=5FTYPES=20The?= =?UTF-8?q?=20fields=20in=20the=20Template=20class=20were=20previously=20s?= =?UTF-8?q?orted=20by=20DIRECT=5FTYPES,=20which=20caused=20issues=20when?= =?UTF-8?q?=20fields=20had=20the=20same=20field=5Ftype.=20Sorting=20alphab?= =?UTF-8?q?etically=20first=20ensures=20that=20fields=20are=20sorted=20in?= =?UTF-8?q?=20a=20consistent=20manner=20before=20sorting=20by=20DIRECT=5FT?= =?UTF-8?q?YPES.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/template/base.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/template/template/base.py b/src/backend/langflow/template/template/base.py index 8c9073df2..c680fd468 100644 --- a/src/backend/langflow/template/template/base.py +++ b/src/backend/langflow/template/template/base.py @@ -20,12 +20,10 @@ class Template(BaseModel): format_field_func(field, name) def sort_fields(self): - # sort fields so that fields that have .field_type in DIRECT_TYPES are first - self.fields.sort( - key=lambda x: DIRECT_TYPES.index(x.field_type) - if x.field_type in DIRECT_TYPES - else 100 - ) + # first sort alphabetically + # then sort fields so that fields that have .field_type in DIRECT_TYPES are first + self.fields.sort(key=lambda x: x.name) + self.fields.sort(key=lambda x: x.field_type in DIRECT_TYPES, reverse=False) def to_dict(self, format_field_func=None): self.process_fields(self.type_name, format_field_func)