#10987 closed enhancement (fixed)
Avoid duplicate info and warning messages
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | 1.0.1 |
Component: | web frontend | Version: | 1.0-stable |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Prevent possibility of multiple identical info or warning messages being presented to the user. |
||
API Changes: | |||
Internal Changes: |
Description
To reproduce the issue I've seen:
- Create an instance of Trac without the
SubversionConnector
component enabled. - Observe that the Warning: Can't synchronize with repository … message is seen.
- Edit a wiki page and save the change.
- Observe that the Warning: Can't synchronize with repository … message is seen twice.
Here are screen captures before and after an edit:
Attachments (6)
Change History (24)
by , 12 years ago
Attachment: | BeforeEdit.png added |
---|
by , 12 years ago
Attachment: | AfterEdit.png added |
---|
by , 12 years ago
Attachment: | t10987-r11483-1.patch added |
---|
comment:1 by , 12 years ago
t10987-r11483-1.patch attempts to fix the issue by preventing duplicate entries in the req.chrome['warnings']
and req.chrome['notices']
lists.
comment:2 by , 12 years ago
I went about trying to fix this under the assumption that we could end up with duplicate info or warning messages displayed under circumstances other than the repository not correctly configured. However, if that is not the case, then it is probably not too important to fix the issue.
comment:3 by , 12 years ago
Milestone: | → 1.0.1 |
---|---|
Owner: | set to |
Status: | new → assigned |
Thanks for the patch.
comment:4 by , 12 years ago
Version: | → 1.0-stable |
---|
comment:6 by , 12 years ago
Owner: | changed from | to
---|
comment:7 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I thought I had tested this patch pretty thoroughly, but I'm still seeing the issue described in comment:description. This seems to be due to the saving/restoring of messages saved in session data to handle the case of redirect. I've created t10987-r11508-1.patch to deal with the issue. Sorry for the error.
comment:8 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | reopened → assigned |
comment:9 by , 12 years ago
Wouldn't there be a way to make sure no duplicate messages get stored in the session in the first place?
comment:10 by , 12 years ago
I'm seeing only one message stored in the session. There is a message popped from req.session
, and another already existing in req.chrome
at line 966 of trac.web.chrome
:
for i in itertools.count(): message = req.session.pop('chrome.%s.%d' % (type_, i)) req.chrome[type_].append(Markup(message))
It looks like we need to make sure there aren't duplicates added when the messages in req.session
are appended to req.chrome
, which is what the patch tries to accomplish.
That said, I'm not claiming to have a big picture view of what's going on in this function, so I wouldn't be surprised if there is a better way to fix this.
by , 12 years ago
Attachment: | 10987-dedupe-messages-r11531.patch added |
---|
Dedupe messages when loading from the session after a redirect.
comment:12 by , 12 years ago
Using unescape()
in t10987-r11508-1.patch isn't quite correct, as req.chrome[type_]
can contain strings or Markup
instances, and the comparison will fail for the latter. We need to compare the messages read from the session to the escaped messages. 10987-dedupe-messages-r11531.patch does this.
But even this isn't completely correct. If a message is read from the session after a redirect, it's stored in req.chrome[type_]
as a Markup
instance. After that, if the same message is added again as a string, it will be duplicated.
How about escaping the messages in add_warning()
and add_notice()
? That way, req.chrome[type_]
will only contain Markup
instances, and the comparison should always work.
Opinions?
follow-up: 14 comment:13 by , 12 years ago
10987-dedupe-markup-r11531.patch implements the suggestion from comment:12.
Opinions?
follow-up: 15 comment:14 by , 12 years ago
Replying to rblank:
10987-dedupe-markup-r11531.patch implements the suggestion from comment:12.
We should add a comment in add_warning
saying that we normalize on Markup instances we have to be wary about the fact that '<a>' == Markup('<a>')
(which is not completely obvious).
Then about the session, doing the escape(sessiondata)
on save and Markup(sessiondata)
on read seems to be a good thing to do. However, shouldn't we rather do that in general, for any session_attribute
, and therefore in Session.get_session/set
? And if we store the session attributes escaped, we should probably use full escaping (keep the default quote=True
).
But if you want to do it the incremental way, we could leave the above suggestion for 1.1.x and fix the present issue like you did in the patch.
follow-up: 17 comment:15 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
10987-dedupe-markup-r11531.patch applied in [11532], with improved docstrings.
Replying to cboos:
Then about the session, doing the
escape(sessiondata)
on save andMarkup(sessiondata)
on read seems to be a good thing to do. However, shouldn't we rather do that in general, for anysession_attribute
, and therefore inSession.get_session/set
? And if we store the session attributes escaped, we should probably use full escaping (keep the defaultquote=True
).
I wouldn't do this for all the data stored in the session. Session attributes can be arbitrary strings (and the DB supports this), so there's no reason to encode or escape them. Why escape e.g. the last ticket query? It wouldn't even work, as escape()
actually modifies the string value, so you would have to call unescape()
when reading the value, not Markup()
.
Also, these messages are the only occurrence I know of of text stored in the session which is used afterward for rendering.
comment:16 by , 12 years ago
Owner: | changed from | to
---|
comment:17 by , 12 years ago
Replying to rblank:
… Why escape e.g. the last ticket query? It wouldn't even work, …
Oh, you're right.
comment:18 by , 12 years ago
Release Notes: | modified (diff) |
---|
Patch against r11483 of the trunk.