You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/08/24 16:51:55 UTC

[GitHub] [airflow] potiuk opened a new pull request, #25944: Fix example branch datetime operator

potiuk opened a new pull request, #25944:
URL: https://github.com/apache/airflow/pull/25944

   The example has been broken because it was comparing naive and
   aware datetime.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25944:
URL: https://github.com/apache/airflow/pull/25944#issuecomment-1227508551

   Looks green


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk merged pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
potiuk merged PR #25944:
URL: https://github.com/apache/airflow/pull/25944


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #25944: Fix example branch datetime operator

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #25944:
URL: https://github.com/apache/airflow/pull/25944#discussion_r954112532


##########
airflow/operators/datetime.py:
##########
@@ -80,12 +80,12 @@ def choose_branch(self, context: Context) -> Union[str, Iterable[str]]:
             now = timezone.make_naive(context["logical_date"], self.dag.timezone)
         else:
             now = timezone.make_naive(timezone.utcnow(), self.dag.timezone)

Review Comment:
   Crossed my mind - I just wasn't sure if there is a deeper meaning to it :)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #25944: Fix example branch datetime operator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25944:
URL: https://github.com/apache/airflow/pull/25944#discussion_r954052705


##########
airflow/operators/datetime.py:
##########
@@ -80,12 +80,12 @@ def choose_branch(self, context: Context) -> Union[str, Iterable[str]]:
             now = timezone.make_naive(context["logical_date"], self.dag.timezone)
         else:
             now = timezone.make_naive(timezone.utcnow(), self.dag.timezone)

Review Comment:
   As far as I can tell the naive `now` is never used, so we can simply remove those `make_naive` calls?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25944:
URL: https://github.com/apache/airflow/pull/25944#issuecomment-1228816030

   @uranusjr :) ? 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #25944: Fix example branch datetime operator

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25944:
URL: https://github.com/apache/airflow/pull/25944#discussion_r954052705


##########
airflow/operators/datetime.py:
##########
@@ -80,12 +80,12 @@ def choose_branch(self, context: Context) -> Union[str, Iterable[str]]:
             now = timezone.make_naive(context["logical_date"], self.dag.timezone)
         else:
             now = timezone.make_naive(timezone.utcnow(), self.dag.timezone)

Review Comment:
   Why not change `target_times_as_date` to take an aware datetime instead?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25944:
URL: https://github.com/apache/airflow/pull/25944#issuecomment-1226131208

   Actually @uranusjr , when I looked at this operator, I realized it needed much more love. It behaved differently when use_logical_date was true /false and the documentation/howto did not even mentinon logical_date usage (even though this is the only "serious" use case which provides idempotency.
   
   I fixed all of that I think (inlcuding the documentation).


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25944:
URL: https://github.com/apache/airflow/pull/25944#discussion_r956989639


##########
airflow/utils/timezone.py:
##########
@@ -206,26 +206,26 @@ def parse(string: str, timezone=None) -> DateTime:
 
 
 @overload
-def coerce_datetime(v: None) -> None:
+def coerce_datetime(v: None, tz: Optional[dt.tzinfo] = None) -> None:
     ...
 
 
 @overload
-def coerce_datetime(v: DateTime) -> DateTime:
+def coerce_datetime(v: DateTime, tz: Optional[dt.tzinfo] = None) -> DateTime:
     ...
 
 
 @overload
-def coerce_datetime(v: dt.datetime) -> DateTime:
+def coerce_datetime(v: dt.datetime, tz: Optional[dt.tzinfo] = None) -> DateTime:
     ...
 
 
-def coerce_datetime(v: Optional[dt.datetime]) -> Optional[DateTime]:
-    """Convert whatever is passed in to an timezone-aware ``pendulum.DateTime``."""
+def coerce_datetime(v: Optional[dt.datetime], tz: Optional[dt.tzinfo] = None) -> Optional[DateTime]:
+    """Convert whatever is passed in to a timezone-aware ``pendulum.DateTime``."""
     if v is None:
         return None
     if isinstance(v, DateTime):
-        return v if v.tzinfo else make_aware(v)
+        return v if v.tzinfo else make_aware(v, tz)
     # Only dt.datetime is left here
     return pendulum.instance(v if v.tzinfo else make_aware(v))

Review Comment:
   This should also use `tz`. (GitHub doesn’t let me suggest a change to unchanged code.)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #25944: Fix BranchDateTimeOperator to be timezone-awreness-insensitive

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25944:
URL: https://github.com/apache/airflow/pull/25944#discussion_r956989639


##########
airflow/utils/timezone.py:
##########
@@ -206,26 +206,26 @@ def parse(string: str, timezone=None) -> DateTime:
 
 
 @overload
-def coerce_datetime(v: None) -> None:
+def coerce_datetime(v: None, tz: Optional[dt.tzinfo] = None) -> None:
     ...
 
 
 @overload
-def coerce_datetime(v: DateTime) -> DateTime:
+def coerce_datetime(v: DateTime, tz: Optional[dt.tzinfo] = None) -> DateTime:
     ...
 
 
 @overload
-def coerce_datetime(v: dt.datetime) -> DateTime:
+def coerce_datetime(v: dt.datetime, tz: Optional[dt.tzinfo] = None) -> DateTime:
     ...
 
 
-def coerce_datetime(v: Optional[dt.datetime]) -> Optional[DateTime]:
-    """Convert whatever is passed in to an timezone-aware ``pendulum.DateTime``."""
+def coerce_datetime(v: Optional[dt.datetime], tz: Optional[dt.tzinfo] = None) -> Optional[DateTime]:
+    """Convert whatever is passed in to a timezone-aware ``pendulum.DateTime``."""
     if v is None:
         return None
     if isinstance(v, DateTime):
-        return v if v.tzinfo else make_aware(v)
+        return v if v.tzinfo else make_aware(v, tz)
     # Only dt.datetime is left here
     return pendulum.instance(v if v.tzinfo else make_aware(v))

Review Comment:
   This should also use `tz`.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org