Upon import, unhandled PermissionError: [Errno 13] Permission denied: 'bcp'
Opened this issue · 1 comments
Attempting to use bcpandas with Airflow (on their 2.8.3-python3.11 image).
The issue seems to happen at the init.py where it tries to check whether bcp is installed. However, if I am understanding the issue correctly, if the default shell is set as sh, then subprocess calls bcp within shell, leading to the "Permission denied" error. I believe there is an option to supply your own path to bcp -- this option should ideally be available somehow before the checks are performed.
Nonetheless, it currently crashes during init.py due to being an unhandled exception. I propose the fix to handle this exception and provide a warning to the user to supply the complete path to bcp. Very open to alternative suggestions!
` File "/opt/airflow/dags/shared/db/mssql.py", line 116, in _load_bcp
from bcpandas import SqlCreds, to_sql
File "/home/airflow/.local/lib/python3.11/site-packages/bcpandas/init.py", line 18, in
run(["bcp", "-v"], stdout=DEVNULL, stderr=DEVNULL, stdin=DEVNULL)
File "/usr/local/lib/python3.11/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 1026, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.11/subprocess.py", line 1953, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'bcp'`
Proposing the following change to the init.py
# BCP check
try:
run(["bcp", "-v"], stdout=DEVNULL, stderr=DEVNULL, stdin=DEVNULL)
except FileNotFoundError:
warnings.warn("BCP utility not installed or not found in PATH, bcpandas will not work!")
except PermissionError:
warnings.warn("BCP utility not found due to permission issues, consider supplying path to bcp or bcpandas will not work!")
except Exception as e:
warnings.warn(f"An unhandled error occurred while checking for BCP utility: {e}")