Skip to content

"apache-airflow-providers-samba" not working with Windows shares due to fixed use of forward slahes #47206

@florianWeCG

Description

@florianWeCG

Apache Airflow version

2.10.5

If "Other Airflow 2 version" selected, which one?

No response

What happened?

When I connect to a Windows share using the samba provider I am receiving a STATUS_INVALID_PARAMETER error when I try to use the "listdir" function.

This is due to the fact that in https://github.com/apache/airflow/blob/main/providers/samba/src/airflow/providers/samba/hooks/samba.py line 88 the path is created using // at the beginning and / as a separator.
When using the smbclient python package directly and typing backward slashes for joining a path, it works without any errors.

What you think should happen instead?

There should be a way to configure the samba provider to use backward slashes instead of forward slashes for joining the path.

How to reproduce

You will need a Windows computer with a network share which can be accessed using a username and password.
E.g. computer name "windowsSharer", share "windowsShare", user "WindowsUser", ...
The connection can then be configured in airflow.
Create a simple dag where the SambaHook is created and the listdir function is called, e.g.:
hook = SambaHook(samba_conn_id=samba_conn_id) files_and_dirs = hook.listdir("windowsDirectory") print(f"{files_and_dirs}")

The listdir function will fail.
However, using smbclient directly like this:
from smbclient import listdir, mkdir, register_session, rmdir, scandir
from smbclient.path import isdir
pathBackSlash = r"\\windowsSharer\windowsShare\windowsDirectory"
for filename in listdir(pathBackSlash, username=r"WindowsUser@Domain", password="secret"):
print(f"{filename}")
Will work, and when you change to forward slashes you get the same "STATUS_INVALID_PARAMETER" message like with the airflow provider.

Operating System

Ubuntu 24.04.2 LTS (in wsl)

Versions of Apache Airflow Providers

apache-airflow-providers-samba==4.9.1

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions