[
https://issues.apache.org/jira/browse/AIRFLOW-3157?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16869745#comment-16869745
]
ASF subversion and git services commented on AIRFLOW-3157:
----------------------------------------------------------
Commit b74db134cab252e7a0b3590015d770fba986a069 in airflow's branch
refs/heads/v1-10-test from Chen Tong
[ https://gitbox.apache.org/repos/asf?p=airflow.git;h=b74db13 ]
[AIRFLOW-2141][AIRFLOW-3157][AIRFLOW-4170] Serialize non-str value by JSON when
importing Variables (#4991)
> Variable.set shouldn't accept types other than string when JSON mode is False
> -----------------------------------------------------------------------------
>
> Key: AIRFLOW-3157
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3157
> Project: Apache Airflow
> Issue Type: Bug
> Affects Versions: 1.10.0
> Reporter: jack
> Priority: Minor
> Fix For: 1.10.4
>
>
> Assume the following code (My xcom contains: {color:#333333}7764615{color} ):
> {code:java}
> def set_last_orderid_variable(ds, **kwargs):
> ti = kwargs['ti']
> new_orderid = ti.xcom_pull(task_ids='get_max_order_id')
> str = "Changed variable from {0} to
> {1}".format(LAST_IMPORTED_ORDER_ID,new_orderid)
> Variable.set('last_order_id_imported', new_orderid)
> logging.info(str)
> return{code}
>
>
> Log shows:
> {code:java}
> [2018-10-04 12:49:48,186] {base_task_runner.py:98} INFO - Subtask:
> [2018-10-04 12:49:38,169] {orders_dag.py:400} INFO - Changed variable from 10
> to 7764615{code}
>
> However When I go to variable
> {code:java}
> 'last_order_id_imported' {code}
> I see empty cell on the Value. *It changed it from 10 to nothing*.
>
>
> If I'll change my code to :
> {code:java}
> def set_last_orderid_variable(ds, **kwargs):
> ti = kwargs['ti']
> new_orderid = ti.xcom_pull(task_ids='get_max_order_id')
> str = "Changed variable from {0} to
> {1}".format(LAST_IMPORTED_ORDER_ID,new_orderid)
> x = '{0}'.format(new_orderid)
> logging.info(type(new_orderid))
> Variable.set('last_order_id_imported', x)
> logging.info(str)
> return{code}
>
>
> This code works.
> When I go to variable
> {code:java}
> 'last_order_id_imported' {code}
> I see {color:#333333}7764615{color}
> The log shows me:
> {code:java}
> [2018-10-04 12:53:58,002] {base_task_runner.py:98} INFO - Subtask:
> [2018-10-04 12:53:58,002] {orders_dag.py:399} INFO - <type 'long'>
> [2018-10-04 12:53:58,032] {base_task_runner.py:98} INFO - Subtask:
> [2018-10-04 12:53:58,031] {orders_dag.py:401} INFO - Changed variable from 10
> to 7764615{code}
>
>
> As you can see the type of new_orderid is
> {code:java}
> long{code}
> . Apparently the
> {code:java}
> Variable.set {code}
> can't handle it (let me remind that this value was received from xcom).
>
>
> If by design Variable.set can accept specific types (strings/ json etc...) it
> should raise exception for others (long etc...) . It shouldn't deicide that
> it puts empty string on it's own and mark the task as success.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)