I have 4 nested classes, see example:
class GameInfo:
id = ""
round = ""
# ... etc
class Opponent:
game_info = GameInfo()
name = ""
# ...
class Tournament:
opponent_list = [] # list of Opponent objects
# ...
class Journal(db.Model):
picked_tournament = db.BlobProperty() # here I put picked Tournament object
the problem is: when I unpickle pickled_tournament in Journal all data from GameInfo is lost. I.e. opponent.name shows correct value, but opponent.game_info.id shows empty string.
I use Google App Engine datastore to store data and picked_tournament is stored in BlobProperty(). To serialize data I invoke: journal.picked_tournament = pickle.dumps(tournament). To load data I use: tournament = pickle.loads(journal.picked_tournament)
Why pickle is not going deeper than 2 levels?
UPD: data is set as follows:
gi = GameInfo()
gi.id = "1234"
opp = Opponent()
opp.name = "John"
opp.game_info = gi
t = Tournament()
t.opponent_list.append(opp)
# etc...
UPD2: just discovered that everything works fine on development server if database is sqlite3, but does not work without sqlite3 and on appspot!
In the constructor for your
Opponentclass, you instantiate a single copy ofGameInfo, which is used by all the instances of that class. For example:Instead, you need to create one for each Opponent instance. Do this by initializing it in the constructor, like this:
Also, since it’s not the 1990s, you really should be using new style classes.