astro-anand opened a new issue, #54097:
URL: https://github.com/apache/airflow/issues/54097

   ### Apache Airflow version
   
   3.0.3
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   numpy float64 subclasses float, so the serialize function [returns the 
object](https://github.com/astro-anand/airflow/blob/3c67878bcc0b92ca041b6442655636af86f35b6e/airflow-core/src/airflow/serialization/serde.py#L124)
 without passing it to the custom numpy serializer. This means that when the 
numpy value is serialized to the xcom backend, it will get coerced to float and 
read back in as a float in subsequent tasks. 
   
   ### What you think should happen instead?
   
   Run the built-in serializer code first, then check if the object is an 
instance of the primitive types. This ensure that a custom serializer would be 
called before returning the object
   
   ### How to reproduce
   
   ```{python}
   import random
   from airflow.sdk import dag, task, Asset, AssetAlias
   
   ALIAS = AssetAlias("s3://alias-example")
   
   TEST_ASSET = Asset("s3://my-bucket/data/file.csv")
   
   
   @dag(tags=["asset_alias_demo"])
   def asset_alias_demo():
   
       @task
       def get_file_ids():
           import numpy as np
           import pandas as pd
   
           return [np.float64(142.13412), np.float64(123.12351242), 
pd.DataFrame({"a": [1, 2, 3]})]
   
       @task(outlets=[TEST_ASSET])
       def add_assets_to_alias(i, outlet_events):
           """
           adds assets to alias
           """
   
           import numpy as np
   
           random_value = random.randint(1, 100)
           print(random_value, "is the random value for file_id:", i)
           print(type(i), "is the type of i")
           print("it is", isinstance(i, np.float64), "that i is a numpy 
float64")
           outlet_events[TEST_ASSET].extra = {
               "file_id": i,
               "random_value": random_value,
           }
           print("the outlet events are", outlet_events)
   ```
   
   running this DAG will show you that the deserialized value of i is not a 
numpy float64
   
   ### Operating System
   
   MacOS
   
   ### Versions of Apache Airflow Providers
   
   N/A
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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-unsubscr...@airflow.apache.org.apache.org

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

Reply via email to