Skip to content

Commit

Permalink
fixed pickle serializer to work in dynamo session store.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaaas committed May 16, 2018
1 parent 7de98b4 commit cb7f72a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions dynamodb_sessions/backends/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

# We'll find some better way to do this.
_DYNAMODB_CONN = None
_DYNAMODB_TABLE = None

logger = logging.getLogger(__name__)
dynamo_kwargs = dict(
Expand Down Expand Up @@ -76,20 +77,25 @@ def dynamodb_connection_factory(low_level=False):
return _DYNAMODB_CONN


def dynamodb_table():
global _DYNAMODB_TABLE

if not _DYNAMODB_TABLE:
_DYNAMODB_TABLE = dynamodb_connection_factory().Table(TABLE_NAME)
return _DYNAMODB_TABLE


class SessionStore(SessionBase):
"""
Implements DynamoDB session store.
"""

def __init__(self, session_key=None):
super(SessionStore, self).__init__(session_key)
self._table = None

@property
def table(self):
if self._table is None:
self._table = dynamodb_connection_factory().Table(TABLE_NAME)
return self._table
return dynamodb_table()

def load(self):
"""
Expand Down
9 changes: 8 additions & 1 deletion dynamodb_sessions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def table(self, force_connection=False):
self._table = dynamodb_connection_factory().Table(TABLE_NAME)
return self._table

@skip("until clear_expired method if implemented")
@override_settings(
SESSION_ENGINE="dynamodb_sessions.backends.dynamodb",
SESSION_COOKIE_AGE=0,
Expand Down Expand Up @@ -409,6 +408,14 @@ def test_clearsessions_command(self):
# ... and one is deleted.
self.assertEqual(1, self.table(force_connection=True).item_count)

def test_pickle_dump(self):
import pickle as pypickle
import cPickle as cpickle

pypickle.dumps(self.session, 2)

cpickle.dumps(self.session, 2)


class CachedDynamoDBTestCase(SessionTestsMixin, TestCase):
backend = CachedDynamoDBSession
Expand Down

0 comments on commit cb7f72a

Please sign in to comment.