Opened 8 years ago
Closed 8 years ago
#12613 closed defect (fixed)
TracSpamFilter causes exception on /about page
Reported by: | Owned by: | Jun Omae | |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.14 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Fix |
||
API Changes: | |||
Internal Changes: |
Description
On visiting /about, I encountered the following exception:
2016-10-24 09:59:10,686 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/about'">, referrer None Traceback (most recent call last): File "/var/www/trac/virtualenv/lib/python2.7/site-packages/trac/web/main.py", line 562, in _dispatch_request dispatcher.dispatch(req) File "/var/www/trac/virtualenv/lib/python2.7/site-packages/trac/web/main.py", line 249, in dispatch resp = chosen_handler.process_request(req) File "/var/www/trac/virtualenv/lib/python2.7/site-packages/trac/about.py", line 66, in process_request data['systeminfo'] = self.env.get_systeminfo() File "/var/www/trac/virtualenv/lib/python2.7/site-packages/trac/env.py", line 304, in get_systeminfo info.extend(provider.get_system_info() or []) File "/var/www/trac/virtualenv/lib/python2.7/site-packages/tracspamfilter/filtersystem.py", line 456, in get_system_info yield 'dnspython', get_pkginfo(dns)['version'] KeyError: 'version'
This is on a standard Debian 8 jessie installation, with python-dnspython 1.12.0-1. The trac.util.get_pkginfo
function returns an empty dict when asking for the version of the module. This in itself might be another bug in Trac or it needs to be fixed in Debian's packaging.
$ python -c 'import dns; from trac.util import get_pkginfo; print get_pkginfo(dns)' {}
Attachments (1)
Change History (7)
by , 8 years ago
Attachment: | tracspamfilter-get-pkginfo.diff added |
---|
comment:1 by , 8 years ago
The attached patch mitigates the problem by using .get('version')
to access the value. Instead of throwing an exception, an empty version will be displayed on the /about page if the version cannot be determined.
comment:2 by , 8 years ago
Hmmm, the python-dnspython package has *.egg-info
metadata however it is single file rather than a directory which contains *.egg-info/PKG-INFO
. The get_pkginfo()
utility doesn't work with metadata as a file.
$ dpkg --listfiles python-dnspython | grep info /usr/lib/python2.7/dist-packages/dnspython-1.12.0.egg-info $ ls -la /usr/lib/python2.7/dist-packages/dnspython-1.12.0.egg-info -rw-r--r--. 1 root root 1280 Sep 15 2014 /usr/lib/python2.7/dist-packages/dnspython-1.12.0.egg-info $ cat /usr/lib/python2.7/dist-packages/dnspython-1.12.0.egg-info Metadata-Version: 1.1 Name: dnspython Version: 1.12.0 Summary: DNS toolkit Home-page: http://www.dnspython.org ...
comment:3 by , 8 years ago
Could you try the following patch?
-
trac/util/__init__.py
diff --git a/trac/util/__init__.py b/trac/util/__init__.py index 2ca6ab62f..605e6bafb 100644
a b def get_pkginfo(dist): 730 730 Always returns a dictionary but it will be empty if no Distribution 731 731 instance can be created for the given module. 732 732 """ 733 import email 733 734 import types 734 735 if isinstance(dist, types.ModuleType): 735 def has_resource(dist, resource_name):736 def has_resource(dist, module, resource_name): 736 737 if dist.location.endswith('.egg'): # installed by easy_install 737 738 return dist.has_resource(resource_name) 738 739 if dist.has_metadata('installed-files.txt'): # installed by pip … … def get_pkginfo(dist): 747 748 if dist.has_metadata('RECORD'): # *.dist-info/RECORD 748 749 reader = csv.reader(StringIO(dist.get_metadata('RECORD'))) 749 750 return any(resource_name == row[0] for row in reader) 751 if dist.has_metadata('PKG-INFO'): 752 try: 753 pkginfo = email.message_from_string( 754 dist.get_metadata('PKG-INFO')) 755 if module.__name__ in pkginfo.get_all('Provides', ()): 756 return True 757 except (IOError, email.Errors.MessageError): 758 pass 750 759 toplevel = resource_name.split('/')[0] 751 760 if dist.has_metadata('top_level.txt'): 752 761 return toplevel in dist.get_metadata_lines('top_level.txt') … … def get_pkginfo(dist): 761 770 resource_name += '.py' 762 771 for dist in find_distributions(module_path, only=True): 763 772 if os.path.isfile(module_path) or \ 764 has_resource(dist, resource_name):773 has_resource(dist, module, resource_name): 765 774 break 766 775 else: 767 776 return {} 768 import email769 777 from trac.util.translation import _ 770 778 attrs = ('author', 'author-email', 'license', 'home-page', 'summary', 771 779 'description', 'version')
After the patch:
>>> import dns >>> from trac.util import get_pkginfo >>> pkginfo = get_pkginfo(dns) >>> pkginfo['version'] '1.12.0' >>> pkginfo['summary'] 'DNS toolkit'
comment:5 by , 8 years ago
Component: | plugin/spamfilter → general |
---|---|
Milestone: | plugin - spam-filter → 1.0.14 |
Owner: | changed from | to
Status: | new → assigned |
Thanks for the feedback. I'll apply the patch to 1.0-stable branch (with unit tests if possible).
comment:6 by , 8 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Fixed in [15189] and merged in [15190-15191].
Workaround