shahar1 commented on code in PR #76561:
URL: https://github.com/apache/airflow/pull/76561#discussion_r4502136715


##########
shared/timezones/src/airflow_shared/timezones/rfc3339.py:
##########
@@ -0,0 +1,58 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import re
+from datetime import date, datetime
+
+from pendulum.parsing import parse_iso8601
+
+_RFC3339_DATETIME = re.compile(
+    
r"\d{4}-(?:0[1-9]|1[0-2])-\d{2}T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?"
+    r"(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)",
+    re.ASCII,
+)

Review Comment:
   Thanks for the review Ash,
   Generally I agree that we shouldn't do it - the problem is that Pendulum 
supports __parsing__ of RFC 3339 rather than __validation__.
   For example, `pendulum.parse()` returns a timezone-aware datetime for all of 
these values, and none is valid RFC 3339:
   
   - `2024-01-01T00:00Z` - no seconds
   - `20240101T000000Z` - basic format, with no `-` or `:`
   - `2024-W01-1T00:00:00Z` and `2024-001T00:00:00Z` - week date and ordinal 
date
   - `2024-01-01 00:00:00+00:00` - space instead of `T`
   - `2024-01-01T00:00:00,5Z` - comma before the fraction
   - `2024-01-01T00:00:00+0000` and `2024-01-01T00:00:00+00` - offset not in 
`±HH:MM` form
   - `2024-01-01T00:00:00+24:00` and `2024-01-01T00:00:00+05:60` - offset out 
of range
   
   Pendulum also rejects `2024-01-01t00:00:00z`, but RFC 3339 allows a 
lowercase `t` and `z`.
   
   Regarding speed - the Rust parser is indeed faster, but according to my 
tests only by about 0.2 µs per value. This check runs once per `Param` value, 
so that does not matter in practice.
   The regex is equivalent, up to some improvements, to the one that the 
removed dependency used (see 
https://github.com/naimetti/rfc3339-validator/blob/29b8351ef0174652a75809ffda264270b0f6eba3/rfc3339_validator.py#L15),
 and it is 
[tested](https://github.com/apache/airflow/pull/76561/changes#diff-21af0b79c74879bc16922ff911e0fc43eaca84bd526f1a8231c461aef84a0556R57).
   
   I'd rather keep this small regex, unless you have any better solutions.



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