Skip to content

Commit

Permalink
refactor: Improve variable creation logic in VariableService (#1875)
Browse files Browse the repository at this point in the history
* refactor: Improve variable creation logic in VariableService
  • Loading branch information
ogabrielluiz committed May 10, 2024
1 parent e36901b commit da25678
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/backend/base/langflow/services/variable/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ def initialize_user_variables(self, user_id: Union[UUID, str], session: Session
for var in self.settings_service.settings.variables_to_get_from_environment:
if var in os.environ:
logger.debug(f"Creating {var} variable from environment.")
try:
self.create_variable(
user_id=user_id,
name=var,
value=os.environ[var],
default_fields=[],
_type="Credential",
session=session,
)
except Exception as e:
logger.error(f"Error creating {var} variable: {e}")
if not session.exec(
select(Variable).where(Variable.user_id == user_id, Variable.name == var)
).first():
try:
self.create_variable(
user_id=user_id,
name=var,
value=os.environ[var],
default_fields=[],
_type="Credential",
session=session,
)
except Exception as e:
logger.error(f"Error creating {var} variable: {e}")

else:
logger.info("Skipping environment variable storage.")
Expand Down

0 comments on commit da25678

Please sign in to comment.