code: def sqlalch_datetime(dt):
      
      if isinstance(dt, str):
          return datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=UTC)
      if dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None:
          return dt.astimezone(UTC)
      return dt.replace(tzinfo=UTC)
docs: Convert a SQLAlchemy datetime string to a datetime object.