From 3862afc907cd065d6dd27e03d68ec7da767e339b Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Thu, 13 Jun 2024 16:29:00 -0300 Subject: [PATCH] refactor: Sort fields alphabetically and prioritize fields with DIRECT_TYPES in Template class Sort the fields alphabetically and prioritize fields with DIRECT_TYPES in the Template class. This improves the organization and readability of the code, ensuring that fields with specific types are listed first. --- src/backend/base/langflow/template/template/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/template/template/base.py b/src/backend/base/langflow/template/template/base.py index 72eb53fc2..ef6082cf8 100644 --- a/src/backend/base/langflow/template/template/base.py +++ b/src/backend/base/langflow/template/template/base.py @@ -23,7 +23,9 @@ class Template(BaseModel): # 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) + self.fields.sort( + key=lambda x: x.field_type in DIRECT_TYPES if hasattr(x, "field_type") else False, reverse=False + ) @model_serializer(mode="wrap") def serialize_model(self, handler):