Commit d22251af authored by Yusei Tahara's avatar Yusei Tahara

Update comment. Explain original purpose of asContext.

parent 0ef6dda6
...@@ -2560,8 +2560,10 @@ class Base( CopyContainer, ...@@ -2560,8 +2560,10 @@ class Base( CopyContainer,
security.declarePublic('asContext') security.declarePublic('asContext')
def asContext(self, context=None, REQUEST=None, **kw): def asContext(self, context=None, REQUEST=None, **kw):
""" """
Allows to have a kind of temp copy of an object edited with kw The purpose of asContext is to allow users overloading easily the properties and categories of
  • Thank you @yusei for improved documentation! This structure is exactly how it "should" be. (what it is and why I want to use it, warnings, example)

Please register or sign in to reply
parameters. This is somewhat equivalent to use tempObject. an existing persistent object. (Use the same data and create a different portal type instance)
Pay attention, to use asContext to create a temp object is wrong usage.
ex : joe_person = person_module.bob_person.asContext(first_name='Joe') ex : joe_person = person_module.bob_person.asContext(first_name='Joe')
""" """
...@@ -2578,13 +2580,8 @@ class Base( CopyContainer, ...@@ -2578,13 +2580,8 @@ class Base( CopyContainer,
temp_object=True, temp_object=True,
is_indexable=False) is_indexable=False)
# Attention! Here all contents of self.__dict__ are # Pass all internal data to new instance. Do not copy, but
# passed to context. This means that if self contains # pass the same data. This is on purpose.
# persistent object, it may be modified through the context.
# And if context is cached on memory, ConnectionStateError
# may occur. Thus this is very dangerous code.
# If asContext is expected to return a copied temporary object,
# copy.deepcopy must be used here.
context.__dict__.update(self.__dict__) context.__dict__.update(self.__dict__)
# Copy REQUEST properties to self # Copy REQUEST properties to self
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment