I'm guessing this has something to do with the order of keys in a dictionary given that dictionaries are unordered data structures. So sometimes the session will load itself with a different order triggering the overwrite. In fact in globals.py we have a sorting_dumps function defined but it doesn't seem to be used anywhere as Session uses the regular pickle.dumps and not sorting_dumps.I think this is fixable but I'm inclined to think we should actually do a breaking change here. Our sessions are incredibly slow even if they don't write to disk just on account of doing a pickle and a hash every single time.
--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'm guessing this has something to do with the order of keys in a dictionary given that dictionaries are unordered data structures. So sometimes the session will load itself with a different order triggering the overwrite.
Do note that the Session itself still has a __dict__ that will have more than one key so I'm still betting on the order thing.
What do people this about this? I am keen to include the change. I do not think the deepcopy is more expensive than the pickling.
> In very short:
>
> This issue is due to cPickle depends on the objects refcount.
Damn, this is stupid!
Dunno what could be a real solution (hey, it was in the roadmap because we discussed it before) but if you check ANY other framework you'd see two ways:- forcing users to use session only with plain dictionaries (serialized to strings, or json, the difference can be computed with a simple compare)- classes that record when a top-level key has been added/removed/changed but FORCE you to signal any change deeper than the first levelI like the first better just for the "promoting sane defaults" argument: I don't like apps (or coders) that use session heavily with god-knows-what serialized in and out at each and every request.The second one is good too: the core code certainly knows when the session needs to be saved (i.e. a formkey has been added as a CSRF prevention) and the user certainly knows when he alters the session.One thing is sure: I wouldn't want the current session code in web3py nor accept a "web3py won't have session turned on by default" . we just need a simpler interfaceYes, I DO like reading django's, werzeug's and pyramid's, I see what they're doing and I joy at the resulting cleanliness and "leanliness" ... and I see myself writing a backend or overriding the core code in less than a day.
It took actually several days worth to hook web2py up when I wrote the redis-backed one and changes to the underlying module broke what I wrote. Actually there's still a small issue with redis-backed used together with locking because there's no way in web2py to know when a request finished without touching the session.
On Tuesday, March 22, 2016 at 10:01:39 PM UTC+1, Massimo Di Pierro wrote:It sounds too complicated to me. This should be automatic and not decided by the code. There must be a better solution. Let’s all think about it.On Mar 22, 2016, at 7:27 AM, Alex <mrau...@gmail.com> wrote:That sounds like the best solution to me. It's backward compatible and if you care about performance you can manually set the dirty Flag to avoid pickling and hashing.
IMHO the first one is better but it involves a mind-shift web2py's users are not accustomed to: certainly the second one is more "likable" by the current userbase.
Humm if we only allow JSON serializable data we could be even smarter than that, we could have our own Dict and List class that would notify their containing Dict or List object if they were changed, so it would bubble up until the last session Dict would then be dirty (we could override __setitem__ to do this). In the end we could know if the session was dirty or not without making any calculation. This way, there would be no need to check for differences in the end.
--
I'll try to make a very very basic prototype of a Session that would only accept JSON and that would track the changes to its contents next week. So we can do some benchmarking.