astronomer-providers icon indicating copy to clipboard operation
astronomer-providers copied to clipboard

Solution to detect classpath issues in serialize method of Async Trigger

Open phanikumv opened this issue 3 years ago • 2 comments

We need a solution to highlight to the developer whenever an incorrect trigger classpath is used in the serialize method.

We ended up spending unreasonable time to detect this last time, as the task will just show the exception as "Trigger failure" and no other information

Either write a unit test to detect this (or) come up with an alternative approach.

phanikumv avatar Dec 25 '21 04:12 phanikumv

This is now implemented as part of the unit test for the serialization method for each of the async trigger. Refer to a sample implementationn below for the snowflake trigger.

def test_snowflake_trigger_serialization(): """ Asserts that the SnowflakeTrigger correctly serializes its arguments and classpath. """ trigger = SnowflakeTrigger( task_id=TASK_ID, polling_period_seconds=POLLING_PERIOD_SECONDS, query_ids=[], snowflake_conn_id="test_conn", ) classpath, kwargs = trigger.serialize() assert classpath == "astronomer_operators.snowflake.triggers.snowflake_trigger.SnowflakeTrigger" assert kwargs == { "task_id": TASK_ID, "polling_period_seconds": 1.0, "query_ids": [], "snowflake_conn_id": "test_conn", }

phanikumv avatar Feb 11 '22 12:02 phanikumv

Traceback (most recent call last):

File "/usr/local/lib/python3.9/site-packages/***/utils/module_loading.py", line 35, in import_string return getattr(module, class_name)

AttributeError: module 'astronomer.providers.microsoft.azure.triggers.data_factory' has no attribute 'WasbToSynpaseTrigger'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/local/lib/python3.9/site-packages/***/jobs/triggerer_job.py", line 406, in update_triggers trigger_class = self.get_trigger_by_classpath(new_triggers[new_id].classpath)

File "/usr/local/lib/python3.9/site-packages/***/jobs/triggerer_job.py", line 423, in get_trigger_by_classpath self.trigger_cache[classpath] = import_string(classpath)

File "/usr/local/lib/python3.9/site-packages/***/utils/module_loading.py", line 37, in import_string raise ImportError(f'Module "{module_path}" does not define a "{class_name}" attribute/class')

ImportError: Module "astronomer.providers.microsoft.azure.triggers.data_factory" does not define a "WasbToSynpaseTrigger" attribute/class

rajaths010494 avatar Aug 10 '22 10:08 rajaths010494

in airflow trigger now sends the error message with import error mentioned in the above comment,

rajaths010494 avatar Sep 19 '22 07:09 rajaths010494