question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with Popen arguments passed as map

See original GitHub issue

Greetings!

I am having an issue when using the package sorl.thumbnail on a Django project. That package produces thumbnails from images using system installed programs (called engines.)

When sorl.thumbnail makes a Popen call here:

https://github.com/jazzband/sorl-thumbnail/blob/22ccd9781462a820f963f57018ad3dcef85053ed/sorl/thumbnail/engines/convert_engine.py#L57

The arguments that are received in your patched Popen are not being interpreted correctly. This is the suspect of the problem:

https://github.com/getsentry/sentry-python/blob/2c0a2ea96882adf69742bd7e79e588564ff5b85c/sentry_sdk/integrations/stdlib.py#L143

Arguments are handled in such a way that the original popen crashes when trying to access args[0], as the args parameter is interpreted (or actually becomes) an empty list.

In my opinion, the problem arises because in sorl.thumbnail the arguments to Popen are passed to a map function first, so that a map object is what gets passed as arguments. I am not sure what’s the effect of a map object being received in your *a of the patched Popen.

Here’s the relevant part of the traceback I am getting:

File "/mnt/d/Proyectos/ginseng/.venv/lib/python3.6/site-packages/sorl/thumbnail/base.py", line 131, in get_thumbnail
    thumbnail)
  File "/mnt/d/Proyectos/ginseng/.venv/lib/python3.6/site-packages/sorl/thumbnail/base.py", line 164, in _create_thumbnail
    default.engine.write(image, options, thumbnail)
  File "/mnt/d/Proyectos/ginseng/.venv/lib/python3.6/site-packages/sorl/thumbnail/engines/convert_engine.py", line 57, in write
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/mnt/d/Proyectos/ginseng/.venv/lib/python3.6/site-packages/sentry_sdk/integrations/stdlib.py", line 165, in sentry_patched_popen_init
    return old_popen_init(self, *a, **kw)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1248, in _execute_child
    executable = args[0]
IndexError: list index out of range

If I remove the Sentry integration altogether from the Django project, sorl.thumbnail is able to effectively call Popen with the “mapped” arguments, and everything works.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Aug 6, 2019

@WilliamMayor to be clear we will fix the SDK to not change the real-world behavior of subprocess, so if your end goal here is to get a newer version of the SDK working again, just wait for a release. I am just saying that those upstream libraries are also broken in the sense that they use the stdlib in an undocumented way and are unlikely to work on PyPy, and I would apprechiate it if somebody went to those projects and made their maintainers aware. There seem to be multiple of them.

1reaction
WilliamMayorcommented, Jul 30, 2019

I experienced this with Django’s collectstatic command running pysassc. I had to downgrade to version 0.9.5 (the last working version I’d used) to get my Heroku deploys to start working again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python subprocess.Popen fails with multiple arguments ...
Question : As you can see, I have a reusable method called RunSubProcess which takes the command as the first parameter and the...
Read more >
subprocess — Subprocess management — Python 3.11.1 ...
The input argument is passed to Popen.communicate() and thus to the subprocess's ... If env is not None , it must be a...
Read more >
Python Tutorial: subprocesses module - 2020 - BogoToBogo
The command line arguments are passed as a list of strings, which avoids the need for escaping quotes or other special characters that...
Read more >
17.1. subprocess - Python 2.7.9 documentation - CodeChef
Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that a pipe to the standard...
Read more >
Python calling Python via subprocess
The issue arises when environment variables are passed in via the env= argument to Python subprocess. In general, one should add or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found