Skip to content

[functions] Use std lib zipfile to check if python function is a .py or a .zip#9773

Closed
mauza wants to merge 2 commits intoapache:masterfrom
mauza:master
Closed

[functions] Use std lib zipfile to check if python function is a .py or a .zip#9773
mauza wants to merge 2 commits intoapache:masterfrom
mauza:master

Conversation

@mauza
Copy link

@mauza mauza commented Mar 1, 2021

When running a python function in pulsar on a broker don't rely on the extension to tell if the file is a zipfile or not but use the built in zipfile.is_zipfile(filepath) function to check.

Motivation

Automation using the pulsar admin api saves python zip files as .py files which breaks when running the function on a broker because python_instance_main.py only checks if they file has a .zip extension for it to extract all the contents.

Modifications

Changed the conditional that checks for a .zip extensions to now use zipfile.is_zipfile

Verifying this change

  • [?] Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests). <---- I'm guessing

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (don't know)

Documentation

  • Does this pull request introduce a new feature? (no)

When running a python function in pulsar on a broker
don't rely on the extension to tell if the file is a
zipfile or not but use the built in zipfile.is_zipfile
function to check.
@mauza
Copy link
Author

mauza commented Mar 1, 2021

After testing with this change locally it doesn't seem to be helping my problem. Closing PR.

@mauza mauza closed this Mar 1, 2021
@mauza
Copy link
Author

mauza commented Mar 2, 2021

I actually think this still may be a fix.

@mauza mauza reopened this Mar 2, 2021
@zymap zymap added this to the 2.8.0 milestone Mar 2, 2021
zpfile.extractall(os.path.dirname(str(args.py)))
sys.path.insert(0, os.path.dirname(str(args.py)))
elif os.path.splitext(str(args.py))[1] == '.zip':
elif zipfile.is_zipfile(str(args.py)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm new to contributing so any direction on how to go about doing that would be helpful, but I'll dive in see if I can figure out how to create some tests around this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take a look at test_python_instance.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zymap I think we don't test 3rd-party dependency for their own functionality :)

@codelipenghui codelipenghui modified the milestones: 2.8.0, 2.9.0 May 21, 2021
@eolivelli eolivelli modified the milestones: 2.9.0, 2.10.0 Oct 6, 2021
@codelipenghui codelipenghui modified the milestones: 2.10.0, 2.11.0 Jan 18, 2022
@codelipenghui
Copy link
Contributor

The pr had no activity for 30 days, mark with Stale label.

@codelipenghui codelipenghui modified the milestones: 2.11.0, 2.12.0 Jul 26, 2022
@tisonkun
Copy link
Member

It seems the author deleted the patch branch.

Closed as stale.

@tisonkun tisonkun closed this Nov 11, 2022
@tisonkun
Copy link
Member

Although, I think it's good to have. So if anyone continue this patch, I'm glad to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants