ferruzzi commented on code in PR #45551:
URL: https://github.com/apache/airflow/pull/45551#discussion_r1913630603


##########
providers/src/airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -165,7 +165,13 @@ def _get_unique_name(
             if fail_if_exists:
                 raise AirflowException(f"A SageMaker {resource_type} with name 
{name} already exists.")
             else:
-                name = f"{proposed_name}-{time.time_ns()//1000000}"
+                timestamp = time.time_ns()//1000000
+                timestamp_length = len(timestamp)
+                name_length = len(name) 
+                if 63 > name_length + timestamp_length + 1: 

Review Comment:
   This feels overly complicated and it isn't immediately obvious where the 63 
is coming from, why are we adding one, what's the 62 down below, etc. 
   
   I'm also fairly certain that `timestamp_length = len(timestamp)` should fail 
because you can't len() an int, and we already know the len because that is 
what that `//1000000` is doing.
   
   String slicing will only truncate if the string is too long, so maybe it 
would be more clear if you did something like:
   
   ```
   max_name_len = 64
   timestamp_len = 13
   
   timestamp = str(time.time_ns())[:timestamp_len]   # We don't actually care 
if it's an int or a str in this case and this will result in the same value as 
str(time.time_ns()//1000000) but is more clear what we're doing.  
   
   
   name = f"{proposed_name[:max_name_len - timestamp_len]}-{timestamp}"  # This 
will only shorten the proposed name if it is longer than (api_max_name - 
timestamp_len)
   ```
   
   then it would use it as-provided unless it is too long.



-- 
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