I posted this as a question on SO: http://stackoverflow.com/questions/35068300/ and was answered it may be a bug, so here it is:
In a request, I set a dictionary in session['test']:
session['test'] = {'test': {'test': {'test':0}}}
Next iteration, session is read back from MongoDB, but the dict has become a <class 'mongoengine.base.datastructures.BaseDict'> which is immutable. Trying to modify it raises
ReferenceError: weakly-referenced object no longer exists
I can cast to a dict but it is not recursive.
print(type(session['test']))
print(type(session['test']['test']))
print(type(session['test']['test']['test']))
test = dict(session['test'])
print(type(test))
print(type(test['test']))
print(type(test['test']['test']))
prints
<class 'mongoengine.base.datastructures.BaseDict'>
<class 'mongoengine.base.datastructures.BaseDict'>
<class 'mongoengine.base.datastructures.BaseDict'>
<class 'dict'>
<class 'mongoengine.base.datastructures.BaseDict'>
<class 'mongoengine.base.datastructures.BaseDict'>
This does not happen with cookie session storage.
- Is this a limitation of
MongoEngineSessionInterface (as opposed to cookie interface)?
- Am I doing things wrong? The doc about
MongoEngineSessionInterface is a bit short.
- Am I misusing
session trying to cram to many data in it?
The point is I can read or replace a key in session but I can't modify it anymore.
Steve Rossiter said:
Some garbage collection is going on between requests and the BaseDict instances that are created get destroyed but the references live on because BaseDict uses weakref.proxy. Then when you call BaseDict.setitem the exception is thrown. This might be something that can be fixed inside flask-mongoengine if you file an issue.
I posted this as a question on SO: http://stackoverflow.com/questions/35068300/ and was answered it may be a bug, so here it is:
In a request, I set a dictionary in
session['test']:Next iteration, session is read back from MongoDB, but the
dicthas become a<class 'mongoengine.base.datastructures.BaseDict'>which is immutable. Trying to modify it raisesI can cast to a
dictbut it is not recursive.prints
This does not happen with cookie session storage.
MongoEngineSessionInterface(as opposed to cookie interface)?MongoEngineSessionInterfaceis a bit short.sessiontrying to cram to many data in it?The point is I can read or replace a key in
sessionbut I can't modify it anymore.Steve Rossiter said: