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

[SNOW-1331499] Fixed ZIP packaging of snowpark project dependencies containing implicit namespace packages #1160

Merged

Conversation

sfc-gh-pjob
Copy link
Contributor

@sfc-gh-pjob sfc-gh-pjob commented Jun 5, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

  • Fixed ZIP packaging of snowpark project dependencies containing implicit namespace packages

Context

The following set of instructions did not work (and it still doesn't work but because of other issue):

snow snowpark init
cd example_snowpark/
snow snowpark build --ignore-anaconda --allow-shared-libraries
snow snowpark deploy --replace

For Python < 3.12, snowpark deploy was failing with the following error:

100357 (P0000): 01b3c0b8-0000-d72d-0000-0f2d04eccd5a: Python Interpreter Error:
ModuleNotFoundError: No module named 'snowflake' in function HELLO_PROCEDURE with handler procedures.hello_procedure

The problem with visibility of snowflake package is caused by the following circumstances:

  • snowflake package being a part of two libraries (snowflake_connector_python and snowflake_snowpark_python) which are dependencies of our template project, is an implicit namespace package. It a regular case, so nothing wrong here.
  • Implicit namespace packages are just directories with subdirectories/files without any __init__.py file, so the zip built by snowpark build contains snowflake directory without __init__.py but with connector and snowpark subdirectories. It looks and it is ok, nothing wrong here.
  • Snowpark uses zipimport to load code from ZIPs uploaded to stages and because of that it inherits all the limitations of zipimport (Snowpark Python code limitations)
  • ZipImport has issues with importing implicit namespace packages if paths to directories representing them are not added explicitly to ZIP archive as separate entries. See: https://bugs.python.org/issue36740
  • We were not adding separate entries with paths to directories to ZIP archive, so zipimport wasn't able to load snowflake namespace package correctly (tested also locally). This is what is changing in this PR - we're starting to add paths to directories as separate entries to ZIP archive.

--

Additional comment 1:

The set of instructions presented at the beginning of this description probably still won't work because snowflake_snowpark_python depends on cryptography which contains shared libraries and this is a known case to receive the following error if differences (OS, python version) between local and target environment appear (see similar issue for AWS lambda):

[AttributeError: module 'cryptography.hazmat.bindings._rust.openssl' has no attribute 'hashes'](https://github.com/pyca/cryptography/issues/8995#top)

Despite the fact that this PR doesn't fix everything, it is still needed to fix handling of namespace packages other than snowflake.

Additional comment 2:
For Python 3.12, snowpark build fails because there is no snowflake-snowpark-python for Python 3.12 while it is required to be downloaded because of --ignore-anaconda flag.

@sfc-gh-pjob sfc-gh-pjob marked this pull request as ready for review June 5, 2024 15:26
@sfc-gh-pjob sfc-gh-pjob requested a review from a team as a code owner June 5, 2024 15:26
RELEASE-NOTES.md Outdated Show resolved Hide resolved
Co-authored-by: Tomasz Urbaszek <tomasz.urbaszek@snowflake.com>
@sfc-gh-pjob sfc-gh-pjob enabled auto-merge (squash) June 10, 2024 10:58
@sfc-gh-pjob sfc-gh-pjob merged commit 06eb35b into main Jun 10, 2024
24 checks passed
@sfc-gh-pjob sfc-gh-pjob deleted the pjob/SNOW-1331499-fix-zip-for-implicit-namespace-packages branch June 10, 2024 11:20
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants