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

TypeError: '_NamespacePath' object is not subscriptable #691

Closed
Amwam opened this issue Oct 29, 2021 · 5 comments · Fixed by #692
Closed

TypeError: '_NamespacePath' object is not subscriptable #691

Amwam opened this issue Oct 29, 2021 · 5 comments · Fixed by #692

Comments

@Amwam
Copy link

Amwam commented Oct 29, 2021

Looks like it was related to this change: https://github.com/scoutapp/scout_apm_python/pull/668/files

I'm not entirely sure what causes this.
We're also using a custom integration, incase thats a factor.

The particular module it is trying to load (when we get the exception) is repoze.who.middleware

We've not made changes to our integration, and has been breaking since, 2.21, but is also happening on 2.23.2

Below is a stack trace, starting from when we run .install()

Please let me know if theres anything else I can provide, I'm not sure how to debug this further

scout_apm.api.install(config=scout_config)
File "/usr/local/lib/python3.7/site-packages/scout_apm/compat.py", line 142, in wrapper
 return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/__init__.py", line 45, in install
 launched = CoreAgentManager().launch()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 49, in launch
 self.download()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 58, in download
 self.downloader.download()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 161, in download
 downloaded = self.download_package()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 209, in download_package
 "GET", full_url, preload_content=False, timeout=10.0, retries=3
File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 75, in request
 method, url, fields=fields, headers=headers, **urlopen_kw
File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 96, in request_encode_url
 return self.urlopen(method, url, **extra_kw)
File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 375, in urlopen
 response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/local/lib/python3.7/site-packages/scout_apm/instruments/urllib3.py", line 68, in wrapped_urlopen
 return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.7/contextlib.py", line 119, in __exit__
 next(self.gen)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 134, in span
 self.stop_span()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 122, in stop_span
 stopping_span.annotate()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 258, in annotate
 self.capture_backtrace()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 293, in capture_backtrace
 self.tag("stack", backtrace.capture_backtrace())
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 122, in capture_backtrace
 return list(itertools.islice(walker, LIMIT))
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 24, in filter_frames
 for frame in frames:
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 84, in backtrace_walker
 yield {"file": filepath(frame), "line": lineno, "function": name}
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 63, in filepath
 return module_filepath(module, filepath)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 40, in module_filepath
 module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]
TypeError: '_NamespacePath' object is not subscriptable
@tim-schilling
Copy link
Collaborator

Hi @Amwam, thanks for the report! Would you be able to provide a way for me to reproduce this? That'd be very helpful in tracking this down.

@Amwam
Copy link
Author

Amwam commented Oct 29, 2021

Hey @tim-schilling I'm not sure I can fully reproduce this in a demo, I can't seem to replicate outside of our main codebase.
However, I was able to get close to the error via a shell

(Python 3.7.5)
pip install repoze.who TurboGears2

>>> import repoze
>>> repoze.__path__
_NamespacePath(['/Users/amit/.pyenv/versions/scout_import_test/lib/python3.7/site-packages/repoze'])
>>> import tg
>>> tg.__path__
['/Users/amit/.pyenv/versions/scout_import_test/lib/python3.7/site-packages/tg']

the import for repoze, returns a _NamespacePath, which isn't subscriptable, whereas the tg import is.
Unfortunately, i don't know enough about this, but maybe its because of how repoze is declaring a namespace here:

https://github.com/repoze/repoze.who/blob/f56f4304562b71cd534ff7cc76b89837d6a4a6bd/repoze/__init__.py#L1-L2

@tim-schilling
Copy link
Collaborator

Excellent, that is very helpful!

@tim-schilling
Copy link
Collaborator

@Amwam if you can test this locally, can you try installing from source using #692 and verify it doesn't throw an error for you any longer?

@Amwam
Copy link
Author

Amwam commented Nov 1, 2021

@tim-schilling Thanks for that, looks like this change works for us, not getting any issues running it now

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 a pull request may close this issue.

2 participants