Opened 17 years ago

Closed 17 years ago

#4729 closed (fixed)

SessionWrapper.pop does not set modified flag

Reported by: Ben Slavin <benjamin.slavin@…> Owned by: Adrian Holovaty
Component: Contrib apps Version: dev
Severity: Keywords:
Cc: mir@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In #4338 a pop method was added to the SessionWrapper class.

This method alters the state of the underlying Session object but does not set the modified flag. This prevents the change from being persisted to the database unless SESSION_SAVE_EVERY_REQUEST is set or another modification is made to the Session.

This bug was introduced in [5306].

Attachments (5)

sessionwrapper_pop_modified.patch (438 bytes ) - added by Ben Slavin <benjamin.slavin@…> 17 years ago.
Sets SessionWrapper.modified when SessionWrapper.pop is called
sessionwrapper_pop_modified.2.patch (471 bytes ) - added by Ben Slavin <benjamin.slavin@…> 17 years ago.
Sets SessionWrapper.modified when SessionWrapper.pop finds an item
sessionwrapper_pop_modified.3.patch (1.1 KB ) - added by Chris Beaven 17 years ago.
with tests
ticket_4729__rev_6373.diff (480 bytes ) - added by Ben Slavin 17 years ago.
Updated to new session implementation
ticket_4729__rev_6447.diff (1.7 KB ) - added by Ben Slavin 17 years ago.
Patch for new session implementation, including tests

Download all attachments as: .zip

Change History (19)

by Ben Slavin <benjamin.slavin@…>, 17 years ago

Sets SessionWrapper.modified when SessionWrapper.pop is called

comment:1 by Chris Beaven, 17 years ago

Needs tests: set
Triage Stage: UnreviewedDesign decision needed

Well, technically pop() doesn't guarantee that we are modifying the session. .pop('nonexistantkey', None) isn't doing any modification (just like get() isn't setting self.accessed).

Perhaps it would be better if SessionWrapper._session_cache was a subclass of dict which handled .accessed and .modified` itself...

comment:2 by Ben Slavin <benjamin.slavin@…>, 17 years ago

You're right that .pop() doesn't guarantee modification. This was something that I had considered, but I think it's better to err on the side of safety. I do like your suggestion of subclassing dict, but I don't know if it's necessary.

Re: your comment about .accessed... this actually isn't true. .get() doesn't need to modify .accessed since ._get_session() handles that already.

comment:3 by Collin Grady <cgrady@…>, 17 years ago

self.modified = key in self._session ? :)

by Ben Slavin <benjamin.slavin@…>, 17 years ago

Sets SessionWrapper.modified when SessionWrapper.pop finds an item

comment:4 by Ben Slavin <benjamin.slavin@…>, 17 years ago

Collin... bah! ;-)

I've attached a new patch with self.modified = self.modified or key in self._session

comment:5 by Chris Beaven, 17 years ago

Is it worth fixing .get in the same ticket or should we open a new one?

comment:6 by Ben Slavin <benjamin.slavin@…>, 17 years ago

If we decide to change .get we actually have to make a number of changes... __getitem__, keys, items, get. We'd also have to change the functionality of _get_session and would require anyone accessing ._session elsewhere to manually set .accessed (I don't know if this is done in practice anywhere).

Because of all the items touched, I think that it might be better to open another ticket, but I'm not convinced that the current behavior of ._get_session is problematic.

by Chris Beaven, 17 years ago

with tests

comment:7 by Chris Beaven, 17 years ago

Needs tests: unset
Triage Stage: Design decision neededReady for checkin

Actually, I was getting confused. .get does set .accessed, since it uses the ._session property.

There's not much to decide upon in this ticket, it's an obvious problem. I'm promoting to checkin

comment:8 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: newclosed

(In [5592]) Fixed #4729 -- SessionWrapper.pop now sets modified flag if necessary. Thanks, Ben Slavin, SmileyChris and Collin Grady

by Ben Slavin, 17 years ago

Attachment: ticket_4729__rev_6373.diff added

Updated to new session implementation

comment:9 by Ben Slavin, 17 years ago

Resolution: fixed
Status: closedreopened

[6333] reintroduced this issue.

Patch has been included.

comment:10 by Michael Radziej, 17 years ago

Cc: mir@… added

comment:11 by Gary Wilson, 17 years ago

Needs tests: set
Triage Stage: Ready for checkinAccepted

The tests also need some alteration so that there is a failure seen before the application of this patch.

by Ben Slavin, 17 years ago

Attachment: ticket_4729__rev_6447.diff added

Patch for new session implementation, including tests

comment:12 by Ben Slavin, 17 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

Attached a new patch.

Promoting to 'ready for checkin' because the tests existed prior to [6333] but were erroneously deleted in the new session implementation (which is why this problem reappeared).

comment:13 by Thomas Güttler <hv@…>, 17 years ago

Tests look good. Please commit.

comment:14 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [6558]) Fixed #4729 -- Restored functionality to the Session class so that popping a
value marks it as modified. This was accidentally lost in the changes in
[6333]. Thanks, hawkeye.

Note: See TracTickets for help on using tickets.
Back to Top