Modify

#13206 closed defect (fixed)

AttributeError: can't set attribute

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Component: ArchiveViewerPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.2

Description

How to Reproduce

While doing a GET operation on /zip/attachment/wiki/WikiStart/ArchiveViewer-0.1-py2.7.egg!/EGG-INFO/SOURCES.txt, Trac issued an internal error.

(please provide additional details here)

Request parameters:

{'attachment': <Resource u'wiki:WikiStart, attachment:ArchiveViewer-0.1-py2.7.egg'>,
 'format': None,
 'path': u'!/EGG-INFO/SOURCES.txt'}

User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0

System Information

Trac 1.2.2.dev0
Babel 2.4.0
Docutils 0.13.1
Genshi 0.7 (with speedups)
GIT 2.13.1
Pygments 2.2.0
pysqlite 2.6.0
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
pytz 2017.2
setuptools 35.0.2
SQLite 3.19.2
Subversion 1.9.5 (r1770682)
Textile 2.3.11
jQuery 1.11.3
jQuery UI 1.11.4
jQuery Timepicker 1.5.5

Enabled Plugins

ArchiveViewer 0.1

Interface Customization

Python Traceback

Traceback (most recent call last):
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/main.py", line 623, in _dispatch_request
    dispatcher.dispatch(req)
  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/main.py", line 239, in dispatch
    resp = chosen_handler.process_request(req)
  File "/Users/rjollos/Documents/Workspace/trac-dev/trac-hacks/archiveviewerplugin/1.0/archiveviewer/zip.py", line 245, in process_request
    attachment.resource = context.resource
AttributeError: can't set attribute

Attachments (1)

Screen Shot 2017-06-07 at 18.57.30.png (52.6 KB) - added by Ryan J Ollos 23 months ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 23 months ago by Ryan J Ollos

Reporter: changed from user1 to Ryan J Ollos

Changed 23 months ago by Ryan J Ollos

comment:2 Changed 23 months ago by Ryan J Ollos

Attachment.resource is a property since Trac 1.1.4: trac:r13487.

On Trac 1.0-stable the parent resource is a link to the egg file:

Proposed fix:

  • archiveviewer/zip.py

     
    242242                fileobj, zipinfo.file_size, mime_type, name, rawurl,
    243243                 annotations=['lineno'])
    244244            if attachment:
    245                 attachment.resource = context.resource
     245
     246                try:
     247                    attachment.resource = context.resource
     248                except AttributeError:  # Trac >= 1.1.4
     249                    class _ZipAttachment(Attachment):
     250
     251                        @property
     252                        def resource(self):
     253                            return Resource(self.parent_resource) \
     254                                   .child(self.realm, self.filename)
     255
     256                        def __init__(self, attachment, resource):
     257                            self.description = attachment.description
     258                            self.size = attachment.size
     259                            self.date = attachment.date
     260                            self.author = attachment.author
     261                            if hasattr(attachment, 'ipnr'):
     262                                self.ipnr = attachment.ipnr
     263                            self.filename = resource.id
     264                            self.parent_realm = resource.parent.realm
     265                            self.parent_id = resource.parent.id
     266                            self.parent_resource = resource.parent
     267
     268                    attachment = _ZipAttachment(attachment, context.resource)
     269
    246270                data = {'preview': preview,
    247                     'attachment': attachment}
     271                        'attachment': attachment}
    248272                return 'attachment.html', data, None
    249273            elif browser:
    250274                path_links = get_path_links(req.href, reponame, path, rev)

comment:3 Changed 23 months ago by Ryan J Ollos

Status: assignedaccepted

comment:4 Changed 23 months ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 16654:

TracArchiveViewer 0.2dev: Fix AttributeError with Trac 1.1.4+

Fixes #13206.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.