[ 
https://issues.apache.org/jira/browse/AIRFLOW-1177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16168961#comment-16168961
 ] 

ASF subversion and git services commented on AIRFLOW-1177:
----------------------------------------------------------

Commit 6069075a7523794f626148b99992687e56e447b8 in incubator-airflow's branch 
refs/heads/v1-8-test from [~ashb]
[ https://git-wip-us.apache.org/repos/asf?p=incubator-airflow.git;h=6069075 ]

[AIRFLOW-1177] Fix Variable.setdefault w/existing JSON

Previously due to a logic error if you attempt to
use
`Variable.setdefault()` with
`deserialize_json=True` and the value
already existed it would die with:

    ...
        my = Variable.setdefault('regions', ['uk'],
deserialize_json=True)
      File "/usr/local/lib/python3.5/site-
packages/airflow/models.py", line 3623, in
setdefault
        return json.loads(obj.val)
    AttributeError: 'str' object has no attribute
'val'

The problem was that the `Variable.get()` call was
returning the value,
not a variable object.

Closes #2540 from ashb/variable-setdefault-json

(cherry picked from commit 610f68b22a8277f9521d0b9989b4dd5ce7cbcfe0)
Signed-off-by: Bolke de Bruin <bo...@xs4all.nl>


> variable json deserialize does not work at set defaults
> -------------------------------------------------------
>
>                 Key: AIRFLOW-1177
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-1177
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: models
>    Affects Versions: Airflow 1.8
>            Reporter: barak schoster
>            Assignee: barak schoster
>             Fix For: 1.9.0, 1.8.3
>
>
> at line:
> https://github.com/apache/incubator-airflow/blob/master/airflow/models.py#L3685
> obj has no attribute val, it is the val itself.
> it will throw error like:
> Variable.setdefault("some_key", 
> deserialize_json=True,default=json.dumps(default_dag_variables))
>   File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 3586, 
> in setdefault
>     return json.loads(obj.val)
> AttributeError: 'unicode' object has no attribute 'val'



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to