shubhamraj-git commented on code in PR #45089:
URL: https://github.com/apache/airflow/pull/45089#discussion_r1893559986


##########
airflow/api_fastapi/core_api/routes/public/variables.py:
##########
@@ -166,6 +167,21 @@ def post_variable(
     session: SessionDep,
 ) -> VariableResponse:
     """Create a variable."""
+    # Check for key length limit
+    if len(post_body.key) > ID_LEN:
+        raise HTTPException(
+            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+            detail=f"Variable key exceeds maximum length of {ID_LEN} 
characters.",
+        )

Review Comment:
   I kept it at 250, since this was given on the API before, also used the same 
const to keep single source of truth.



##########
airflow/api_fastapi/core_api/routes/public/variables.py:
##########
@@ -166,6 +167,21 @@ def post_variable(
     session: SessionDep,
 ) -> VariableResponse:
     """Create a variable."""
+    # Check for key length limit
+    if len(post_body.key) > ID_LEN:
+        raise HTTPException(
+            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+            detail=f"Variable key exceeds maximum length of {ID_LEN} 
characters.",
+        )
+
+    # Check if the key already exists
+    existing_variable = session.scalar(select(Variable).where(Variable.key == 
post_body.key).limit(1))
+    if existing_variable:
+        raise HTTPException(
+            status_code=status.HTTP_409_CONFLICT,

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to