Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soda_logs used before being declared causes UnboundLocalError #25

Closed
AlessandroLollo opened this issue Aug 22, 2023 · 8 comments
Closed

Comments

@AlessandroLollo
Copy link
Collaborator

          @AlessandroLollo The above issue has been fixed with this PR https://github.com/sodadata/prefect-soda-core/pull/21

But there is this new error

Encountered exception during execution:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/prefect/engine.py", line 1730, in orchestrate_task_run
    result = await call.aresult()
             ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 292, in aresult
    return await asyncio.wrap_future(self.future)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 346, in _run_async
    result = await coro
             ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect_soda_core/tasks.py", line 148, in soda_scan_execute
    return soda_logs
           ^^^^^^^^^
UnboundLocalError: cannot access local variable 'soda_logs' where it is not associated with a value

Finished in state Failed("Task run encountered an exception UnboundLocalError: cannot access local variable 'soda_logs' where it is not associated with a value")

Originally posted by @DVD-99 in #18 (comment)

@DVD-99
Copy link

DVD-99 commented Aug 23, 2023

@AlessandroLollo Here is my code

from prefect import flow, get_run_logger
from prefect_soda_core.soda_configuration import SodaConfiguration
from prefect_soda_core.sodacl_check import SodaCLCheck
from prefect_soda_core.tasks import soda_scan_execute

soda_configuration_block = SodaConfiguration(
        configuration_yaml_path="/app/proto.yml"
    )
soda_run_public = soda_scan_execute(
        data_source_name="landing_public",
        configuration=soda_configuration_block,
        checks=SodaCLCheck(sodacl_yaml_path="/app/public_checks.yml"),
        variables={},
        verbose=True,
        return_state=True
    )
logger.info(soda_run_public)
    if soda_run_public.is_failed():
        pass
if __name__ == "__main__":
    # Deployment Setup
    run_soda_scan()

Make sure to set the atleast one check in public_checks.yml to failure.
Traceback

File "/app/main.py", line 58, in <module>
    run_soda_scan()
  File "/usr/local/lib/python3.8/site-packages/prefect/flows.py", line 560, in __call__
    return enter_flow_run_engine_from_flow_call(
  File "/usr/local/lib/python3.8/site-packages/prefect/engine.py", line 272, in enter_flow_run_engine_from_flow_call
    retval = from_sync.wait_for_call_in_loop_thread(
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/api.py", line 243, in wait_for_call_in_loop_thread
    return call.result()
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/calls.py", line 283, in result
    return self.future.result(timeout=timeout)
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/calls.py", line 169, in result
    return self.__get_result()
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/calls.py", line 346, in _run_async
    result = await coro
  File "/usr/local/lib/python3.8/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
    return await fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine.py", line 375, in create_then_begin_flow_run
    return await state.result(fetch=True)
  File "/usr/local/lib/python3.8/site-packages/prefect/states.py", line 91, in _get_state_result
    raise await get_state_exception(state)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine.py", line 1730, in orchestrate_task_run
    result = await call.aresult()
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/calls.py", line 292, in aresult
    return await asyncio.wrap_future(self.future)
  File "/usr/local/lib/python3.8/site-packages/prefect/_internal/concurrency/calls.py", line 346, in _run_async
    result = await coro
  File "/usr/local/lib/python3.8/site-packages/prefect_soda_core/tasks.py", line 148, in soda_scan_execute
    return soda_logs
UnboundLocalError: local variable 'soda_logs' referenced before assignment

@AlessandroLollo
Copy link
Collaborator Author

Hey @DVD-99 👋
What's the return_state parameter in soda_scan_execute?

@AlessandroLollo
Copy link
Collaborator Author

Hey @fakhavan 👋
Would you be willing to provide some help on this issue?

@DVD-99
Copy link

DVD-99 commented Aug 24, 2023

@AlessandroLollo soda_scan_execute is a task, if we use return_state = True the variable soda_run_public will hold the task's state, whether it is failed or executed, as I'm running multiple soda_scan_execute, I did not want Prefect to stop my flow if one of the task fails.

@AlessandroLollo
Copy link
Collaborator Author

Hey @DVD-99 👋
I should have fixed the issue you're facing in this PR

Before I merge the PR into main, can you give it a try?
Thanks!

@PaoloLeonard
Copy link

It solved the issue for me @AlessandroLollo, thanks

@AlessandroLollo
Copy link
Collaborator Author

Great @PaoloLeonard 🚀

@AlessandroLollo
Copy link
Collaborator Author

Fixed in v0.1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants