Opened 10 years ago
Closed 9 years ago
#11954 closed defect (fixed)
AttributeError: 'Mock' object has no attribute 'args'
Reported by: | bobhy | Owned by: | Steffen Hoffmann |
---|---|---|---|
Priority: | normal | Component: | TagsPlugin |
Severity: | normal | Keywords: | |
Cc: | Ryan J Ollos, Jun Omae | Trac Release: | 1.0 |
Description
How to Reproduce
- Browse to Trac site
- do not log in with a user name
- Click NewTicket
- In New Ticket
- fill in dummy title
- click Create Ticket
- Expect
- ticket created with Reporter Anonymous
- Observe
- this crash.
Syndrome
While doing a POST operation on /newticket
, Trac issued an internal error.
(please provide additional details here)
Request parameters:
{'__FORM_TOKEN': u'63b3923f54d29c902a8dcec8', 'author': u'anonymous', 'field_billable': u'1', 'field_blockedby': u'', 'field_blocking': u'', 'field_cc': u'', 'field_checkbox_billable': u'1', 'field_component': u'sw/Trac', 'field_description': u'', 'field_estimatedhours': u'0', 'field_hours': u'0', 'field_keywords': u'', 'field_milestone': u'', 'field_owner': u'< default >', 'field_parents': u'', 'field_priority': u'major', 'field_reporter': u'anonymous', 'field_summary': u'foo ticket', 'field_type': u'defect', 'submit': u'Create ticket'}
User agent: Mozilla/5#0 #Windows NT 6#1; WOW64; Trident/7#0; SLCC2; #NET CLR 2#0#50727; #NET CLR 3#5#30729; #NET CLR 3#0#30729; Media Center PC 6#0; #NET4#0C; #NET4#0E; rv:11#0# like Gecko
System Information
Trac | 1#0#2beta1
|
Genshi | 0#7 #without speedups#
|
GIT | 1#8#3#msysgit#0
|
pysqlite | 2#6#0
|
Python | 2#7#8 #default, Jun 30 2014, 16:08:48# #MSC v#1500 64 bit #AMD64##
|
setuptools | 3#6
|
SQLite | 3#6#21
|
jQuery | 1#7#2
|
jQuery UI | 1#8#21
|
jQuery Timepicker | 1#0#1
|
Enabled Plugins
BackLinksMacro | 7#0dev-r13928
|
TicketImport | 0#8#3
|
timingandestimationplugin | 1#3#7
|
TracAccountManager | 0#4#4
|
TracIncludeMacro | 3#0#0dev-r13471
|
TracMasterTickets | 3#0#5dev-r13684
|
TracSubTicketsPlugin | 0#2#0#dev-20140826
|
TracTags | 0#8dev-r14041
|
TracTocMacro | 11#0#0#4-r13602
|
Python Traceback
Traceback #most recent call last#: File "f:\home\bob\src\tracstuff\trac\trac\web\main#py", line 506, in _dispatch_request dispatcher#dispatch#req# File "f:\home\bob\src\tracstuff\trac\trac\web\main#py", line 221, in dispatch resp = chosen_handler#process_request#req# File "f:\home\bob\src\tracstuff\trac\trac\ticket\web_ui#py", line 180, in process_request return self#_process_newticket_request#req# File "f:\home\bob\src\tracstuff\trac\trac\ticket\web_ui#py", line 465, in _process_newticket_request self#_do_create#req, ticket# # #redirected if successful# File "f:\home\bob\src\tracstuff\trac\trac\ticket\web_ui#py", line 1297, in _do_create ticket#insert## File "f:\home\bob\src\tracstuff\trac\trac\ticket\model#py", line 256, in insert listener#ticket_created#self# File "f:\home\bob\src\tracstuff\tagsplugin\tractags\ticket#py", line 182, in ticket_created ticket, None, ticket#'time'## File "f:\home\bob\src\tracstuff\tagsplugin\tractags\ticket#py", line 143, in set_resource_tags self##set_resource_tags#req, resource, tags# File "f:\home\bob\src\tracstuff\tagsplugin\tractags\api#py", line 312, in set_resource_tags tag_resource#self#env, resource, author=self#_get_author#req#, File "f:\home\bob\src\tracstuff\tagsplugin\tractags\api#py", line 334, in _get_author author = get_reporter_id#req, 'author'# File "f:\home\bob\src\tracstuff\trac\trac\util\__init__#py", line 58, in get_reporter_id r = req.args.get#arg_name# AttributeError: 'Mock' object has no attribute 'args'
Attachments (1)
Change History (13)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
You shall get a similar error when changing ticket keywords then. Can you confirm this?
What value has option 'ticket_fields' in you tags
section of trac.ini
, if set at all?
comment:3 Changed 10 years ago by
I see, that the flaw has been introduced by changes to optionally record tag history.
A fix is almost ready, but I still fail to understand, why this case is not covered by tractags.tests.ticket.TicketTagProviderTestCase._create_ticket()
?
comment:5 Changed 10 years ago by
Cc: | Ryan J Ollos Jun Omae added; anonymous removed |
---|
The fix is tested and validated, but I'm still investigating on how to apply unit tests for covering this issue.
Changed 10 years ago by
Attachment: | t11954-unittest.diff added |
---|
comment:6 Changed 10 years ago by
The issue occurs in the following cases:
- Ticket which its reporter is
anonymous
is created. - Ticket comment is added by
anonymous
.
I created patch which covers those cases. See t11954-unittest.diff
comment:7 Changed 10 years ago by
I had a test for anonymous ticket creation, but your code doesn't duplicates code the way I did, and you additionally covered the anonymous comment case. Will move to you solution.
comment:9 Changed 10 years ago by
I've encountered an internal error with the same message as reported in this ticket using r14148 of TagsPlugin and renaming a wiki page:
File "/home/user/Workspace/t11694/teo-rjollos.git/trac/web/main.py", line 512, in _dispatch_request dispatcher.dispatch(req) File "/home/user/Workspace/t11694/teo-rjollos.git/trac/web/main.py", line 221, in dispatch resp = chosen_handler.process_request(req) File "/home/user/Workspace/t11694/teo-rjollos.git/trac/wiki/web_ui.py", line 163, in process_request return self._do_rename(req, page) File "/home/user/Workspace/t11694/teo-rjollos.git/trac/wiki/web_ui.py", line 323, in _do_rename page.rename(new_name) File "/home/user/Workspace/t11694/teo-rjollos.git/trac/wiki/model.py", line 199, in rename listener.wiki_page_renamed(self, old_name) File "/home/user/Workspace/trachacks.git/tagsplugin/trunk/tractags/wiki.py", line 161, in wiki_page_renamed tag_sys.reparent_tags(req, Resource('wiki', page.name), old_name) File "/home/user/Workspace/trachacks.git/tagsplugin/trunk/tractags/api.py", line 516, in reparent_tags provider.reparent_resource_tags(req, resource, old_name, comment) File "/home/user/Workspace/trachacks.git/tagsplugin/trunk/tractags/api.py", line 319, in reparent_resource_tags tag_resource(self.env, resource, old_id, self._get_author(req), File "/home/user/Workspace/trachacks.git/tagsplugin/trunk/tractags/api.py", line 333, in _get_author return get_reporter_id(req, 'author') File "/home/user/Workspace/t11694/teo-rjollos.git/trac/util/__init__.py", line 58, in get_reporter_id r = req.args.get(arg_name)
Copying the change from [14144] fixes the issue.
-
tagsplugin/trunk/tractags/wiki.py
diff --git a/tagsplugin/trunk/tractags/wiki.py b/tagsplugin/trunk/tractags/wiki. index f6f691a..6d7e254 100644
a b class WikiTagInterface(TagTemplateProvider): 157 157 tag_sys = TagSystem(self.env) 158 158 # XXX Ugh. Hopefully this will be sufficient to fool any endpoints. 159 159 from trac.test import Mock, MockPerm 160 req = Mock(a uthname='anonymous', perm=MockPerm())160 req = Mock(args={}, authname='anonymous', perm=MockPerm(), session={}) 161 161 tag_sys.reparent_tags(req, Resource('wiki', page.name), old_name) 162 162 163 163 def wiki_page_deleted(self, page):
It could be nice to add a MockReq
in tractags.util
with suitable defaults. I didn't fully implement that change, but what I had in mind was:
-
tagsplugin/trunk/tractags/util.py
diff --git a/tagsplugin/trunk/tractags/util.py b/tagsplugin/trunk/tractags/util. index f587efb..61a6481 100644
a b 8 8 # 9 9 10 10 import re 11 from functools import partial 12 13 from trac.test import Mock, MockPerm 11 14 12 15 _TAG_SPLIT = re.compile('[,\s]+') 13 16 14 17 18 MockReq = partial(Mock, args={}, authname='anonymous', 19 perm=MockPerm(), session={}) 20 21 15 22 def query_realms(query, all_realms): 16 23 realms = [] 17 24 for realm in all_realms: -
tagsplugin/trunk/tractags/wiki.py
diff --git a/tagsplugin/trunk/tractags/wiki.py b/tagsplugin/trunk/tractags/wiki. index f6f691a..fa8bae7 100644
a b from tractags.compat import to_utimestamp 32 32 from tractags.macros import TagTemplateProvider 33 33 from tractags.model import delete_tags, tag_changes 34 34 from tractags.web_ui import render_tag_changes 35 from tractags.util import query_realms, split_into_tags35 from tractags.util import MockReq, query_realms, split_into_tags 36 36 37 37 38 38 class WikiTagProvider(DefaultTagProvider): … … class WikiTagInterface(TagTemplateProvider): 155 155 self.log.debug("Moving wiki page tags from %s to %s", 156 156 old_name, page.name) 157 157 tag_sys = TagSystem(self.env) 158 # XXX Ugh. Hopefully this will be sufficient to fool any endpoints. 159 from trac.test import Mock, MockPerm 160 req = Mock(authname='anonymous', perm=MockPerm()) 158 req = MockReq()
comment:10 Changed 10 years ago by
Thanks for the pointer.
We'll need some Python2.4 compatibility code for the missing partial
built-in, but I've already found a promising solution and will implement this soonish. Dunno why I didn't watch for more such 'mockup issues' myself, sorry.
comment:11 Changed 10 years ago by
In 14157:
TagsPlugin: Add a versatile Trac request mockup, refs #11954.
This is partially a rework of [14146] using partial
built-in for better
maintainability.
Thanks to Ryan J Ollos for designing and proposing the new utility class.
(manually correcting bad ticket reference in original commit message)
If Log in as authenticated user in step 1, error does not occur.