ferruzzi commented on code in PR #42808:
URL: https://github.com/apache/airflow/pull/42808#discussion_r1793899709


##########
airflow/api_connexion/schemas/task_instance_schema.py:
##########
@@ -69,22 +68,17 @@ class Meta:
     executor = auto_field()
     executor_config = auto_field()
     note = auto_field()
-    sla_miss = fields.Nested(SlaMissSchema, dump_default=None)
     rendered_map_index = auto_field()
     rendered_fields = JsonObjectField(dump_default={})
     trigger = fields.Nested(TriggerSchema)
     triggerer_job = fields.Nested(JobSchema)
 
     def get_attribute(self, obj, attr, default):
-        if attr == "sla_miss":
-            # Object is a tuple of task_instance and slamiss
-            # and the get_value expects a dict with key, value
-            # corresponding to the attr.
-            slamiss_instance = {"sla_miss": obj[1]}
-            return get_value(slamiss_instance, attr, default)
-        elif attr == "rendered_fields":
-            return get_value(obj[0], 
"rendered_task_instance_fields.rendered_fields", default)
-        return get_value(obj[0], attr, default)
+        ti = obj if isinstance(obj, TaskInstance) else obj[0]

Review Comment:
   Without this addition, a handful of tests fail and I can't see where this is 
getting called.  There may be a better way to handle this.
   
   Example failure:
   
   ```
   
   tests/api_connexion/endpoints/test_task_instance_endpoint.py:165 
(TestGetTaskInstance.test_should_respond_200)
   {'rendered_fields': {}} != {'dag_id': 'example_python_operator',
    'dag_run_id': 'TEST_DAG_RUN_ID',
    'duration': 10000.0,
    'end_date': '2020-01-03T00:00:00+00:00',
    'execution_date': '2020-01-01T00:00:00+00:00',
    'executor': None,
    'executor_config': '{}',
    'hostname': '',
    'map_index': -1,
    'max_tries': 0,
    'note': 'placeholder-note',
    'operator': None,
    'pid': 100,
    'pool': 'default_pool',
    'pool_slots': 1,
    'priority_weight': 9,
    'queue': 'default_queue',
    'queued_when': None,
    'rendered_fields': {},
    'rendered_map_index': None,
    'start_date': '2020-01-02T00:00:00+00:00',
    'state': 'running',
    'task_display_name': 'print_the_context',
    'task_id': 'print_the_context',
    'trigger': None,
    'triggerer_job': None,
    'try_number': 0,
    'unixname': 'ferruzzi'}
   
   <Click to see difference>
   
   self = 
<tests.api_connexion.endpoints.test_task_instance_endpoint.TestGetTaskInstance 
object at 0x7f69163cd780>
   session = <sqlalchemy.orm.session.Session object at 0x7f69123377c0>
   
       @provide_session
       def test_should_respond_200(self, session):
           self.create_task_instances(session)
           # Update ti and set operator to None to
           # test that operator field is nullable.
           # This prevents issue when users upgrade to 2.0+
           # from 1.10.x
           # https://github.com/apache/airflow/issues/14421
           session.query(TaskInstance).update({TaskInstance.operator: None}, 
synchronize_session="fetch")
           session.commit()
           response = self.client.get(
               
"/api/v1/dags/example_python_operator/dagRuns/TEST_DAG_RUN_ID/taskInstances/print_the_context",
               environ_overrides={"REMOTE_USER": "test"},
           )
           assert response.status_code == 200
   >       assert response.json == {
               "dag_id": "example_python_operator",
               "duration": 10000.0,
               "end_date": "2020-01-03T00:00:00+00:00",
               "execution_date": "2020-01-01T00:00:00+00:00",
               "executor": None,
               "executor_config": "{}",
               "hostname": "",
               "map_index": -1,
               "max_tries": 0,
               "note": "placeholder-note",
               "operator": None,
               "pid": 100,
               "pool": "default_pool",
               "pool_slots": 1,
               "priority_weight": 9,
               "queue": "default_queue",
               "queued_when": None,
               "start_date": "2020-01-02T00:00:00+00:00",
               "state": "running",
               "task_id": "print_the_context",
               "task_display_name": "print_the_context",
               "try_number": 0,
               "unixname": getuser(),
               "dag_run_id": "TEST_DAG_RUN_ID",
               "rendered_fields": {},
               "rendered_map_index": None,
               "trigger": None,
               "triggerer_job": None,
           }
   E       AssertionError: assert equals failed
   E                                           +{                              
 
   E                                           +  'dag_id': 
'example_python_ope 
   E                                           +rator',                        
 
   E                                           +  'dag_run_id': 
'TEST_DAG_RUN_I 
   E                                           +D',                            
 
   E                                           +  'duration': 10000.0,         
 
   E                                           +  'end_date': 
'2020-01-03T00:00 
   E                                           +:00+00:00',                    
 
   E                                           +  'execution_date': 
'2020-01-01 
   E                                           +T00:00:00+00:00',              
 
   E                                           +  'executor': None,            
 
   E                                           +  'executor_config': '{}',     
 
   E                                           +  'hostname': '',              
 
   E                                           +  'map_index': -1,             
 
   E                                           +  'max_tries': 0,              
 
   E                                           +  'note': 'placeholder-note',  
 
   E                                           +  'operator': None,            
 
   E                                           +  'pid': 100,                  
 
   E                                           +  'pool': 'default_pool',      
 
   E                                           +  'pool_slots': 1,             
 
   E                                           +  'priority_weight': 9,        
 
   E                                           +  'queue': 'default_queue',    
 
   E                                           +  'queued_when': None,         
 
   E          ^{'rendered_fields': {} ^}           ^  'rendered_fields': {} 
^,        
   E                                           +  'rendered_map_index': None,  
 
   E                                           +  'start_date': 
'2020-01-02T00: 
   E                                           +00:00+00:00',                  
 
   E                                           +  'state': 'running',          
 
   E                                           +  'task_display_name': 
'print_t 
   E                                           +he_context',                   
 
   E                                           +  'task_id': 
'print_the_context 
   E                                           +',                             
 
   E                                           +  'trigger': None,             
 
   E                                           +  'triggerer_job': None,       
 
   E                                           +  'try_number': 0,             
 
   E                                           +  'unixname': 'ferruzzi',      
 
   E                                           +}
   
   test_task_instance_endpoint.py:181: AssertionError
   ```



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

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

Reply via email to