]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Fix flush() error with partitioned tables by explicitly setting the PK value.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 11 Nov 2011 15:05:27 +0000 (10:05 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 11 Nov 2011 15:05:27 +0000 (10:05 -0500)
xonstat/models.py
xonstat/views/submission.py

index 08a7cb569fc3f5f454ca4f0308212dccadf922ca..0dcda1fc904815ef1928e81be2c90d661a342849 100755 (executable)
@@ -58,8 +58,9 @@ class Map(object):
 
 
 class Game(object):
-    def __init__(self, start_dt=None, game_type_cd=None, 
+    def __init__(self, game_id=None, start_dt=None, game_type_cd=None, 
             server_id=None, map_id=None, winner=None):
+        self.game_id = game_id
         self.start_dt = start_dt
         self.game_type_cd = game_type_cd
         self.server_id = server_id
@@ -75,7 +76,8 @@ class Game(object):
 
 
 class PlayerGameStat(object):
-    def __init__(self, create_dt=None):
+    def __init__(self, player_game_stat_id=None, create_dt=None):
+        self.player_game_stat_id = player_game_stat_id
         self.create_dt = create_dt
 
     def __repr__(self):
index ea3e5c1a37f5f74b07ea3d83161f0533529b99eb..1cf34933fc5921f03a010c9428b2a7ee7fa5f9d3 100755 (executable)
@@ -5,6 +5,7 @@ import re
 import time\r
 from pyramid.config import get_current_registry\r
 from pyramid.response import Response\r
+from sqlalchemy import Sequence\r
 from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound\r
 from xonstat.d0_blind_id import d0_blind_id_verify\r
 from xonstat.models import *\r
@@ -207,11 +208,11 @@ def create_game(session=None, start_dt=None, game_type_cd=None,
     map_id - map on which the game was played\r
     winner - the team id of the team that won\r
     """\r
-\r
-    game = Game(start_dt=start_dt, game_type_cd=game_type_cd,\r
+    seq = Sequence('games_game_id_seq')\r
+    game_id = session.execute(seq)\r
+    game = Game(game_id=game_id, start_dt=start_dt, game_type_cd=game_type_cd,\r
                 server_id=server_id, map_id=map_id, winner=winner)\r
     session.add(game)\r
-    session.flush()\r
     log.debug("Created game id {0} on server {1}, map {2} at \\r
             {3}".format(game.game_id, \r
                 server_id, map_id, start_dt))\r
@@ -278,7 +279,10 @@ def create_player_game_stat(session=None, player=None,
     # in here setup default values (e.g. if game type is CTF then\r
     # set kills=0, score=0, captures=0, pickups=0, fckills=0, etc\r
     # TODO: use game's create date here instead of now()\r
-    pgstat = PlayerGameStat(create_dt=datetime.datetime.now())\r
+    seq = Sequence('player_game_stats_player_game_stat_id_seq')\r
+    pgstat_id = session.execute(seq)\r
+    pgstat = PlayerGameStat(player_game_stat_id=pgstat_id, \r
+            create_dt=datetime.datetime.now())\r
 \r
     # set player id from player record\r
     pgstat.player_id = player.player_id\r
@@ -335,7 +339,6 @@ def create_player_game_stat(session=None, player=None,
         session.add(game)\r
 \r
     session.add(pgstat)\r
-    session.flush()\r
 \r
     return pgstat\r
 \r