potiuk commented on a change in pull request #19914:
URL: https://github.com/apache/airflow/pull/19914#discussion_r765323415



##########
File path: airflow/utils/timezone.py
##########
@@ -179,8 +179,7 @@ def coerce_datetime(v: Union[None, dt.datetime, DateTime]) 
-> Optional[DateTime]
     """Convert whatever is passed in to an timezone-aware 
``pendulum.DateTime``."""
     if v is None:
         return None
-    if v.tzinfo is None:
-        v = make_aware(v)
     if isinstance(v, DateTime):
-        return v
-    return pendulum.instance(v)
+        return v if v.tzinfo else make_aware(v)

Review comment:
       Very good point. I've added tests and run it  before/after and behaviour 
is the same :)

##########
File path: airflow/utils/db.py
##########
@@ -58,22 +59,28 @@
 
 log = logging.getLogger(__name__)
 
+SESSION_MUST_BE_ASSIGNED = "The session should be assigned here. This is a 
critical assertion."
+
 
 def _format_airflow_moved_table_name(source_table, version):
     return "__".join([settings.AIRFLOW_MOVED_TABLE_PREFIX, 
version.replace(".", "_"), source_table])
 
 
 @provide_session
-def merge_conn(conn, session=None):
+def merge_conn(conn, session: Optional[SASession] = None):
     """Add new Connection."""
+    if not session:
+        raise RuntimeError(SESSION_MUST_BE_ASSIGNED)
     if not session.query(Connection).filter(Connection.conn_id == 
conn.conn_id).first():
         session.add(conn)
         session.commit()
 
 
 @provide_session
-def add_default_pool_if_not_exists(session=None):
+def add_default_pool_if_not_exists(session: Optional[SASession] = None):
     """Add default pool if it does not exist."""
+    if not session:
+        raise RuntimeError(SESSION_MUST_BE_ASSIGNED)

Review comment:
       Corrected.




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