2

I am currently developing a game. This game store data in a sqlite database. I'm using dataset to manage the database, so I don't have to worry about sql queries. I have a method that access the database to update player info :

def updatePlayerInfo(channel, info): # Context at https://github.com/DuckHunt-discord/DuckHunt-Discord/blob/master/database.py#L33
    table = getChannelTable(channel)
    table.upsert(info, ["id_"]) 
    # An UPSERT is a smart combination of insert and update.
    # If rows with matching keys exist they will be updated, otherwise a new row is inserted in the table.

This function works fine for almost everything. Only one thing create an error : using munAP_ as a column name ! (storing only integers timestamps inside) Some other columns work the same way, but aren't affected by a single bug ! Exception raised is the following :

Ignoring exception in on_message
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/discord/client.py", line 245, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "./main.py", line 1022, in on_message
    if database.getStat(message.channel, message.author, "chargeurs",
  File "/home/cloudbot/discord-bot/database.py", line 45, in setStat
    updatePlayerInfo(channel, dict_)
  File "/home/cloudbot/discord-bot/database.py", line 35, in updatePlayerInfo
    table.upsert(info, ["id_"])
  File "/usr/local/lib/python3.4/dist-packages/dataset/persistence/table.py", line 185, in upsert
    row_count = self.update(row, keys, ensure=ensure, types=types)
  File "/usr/local/lib/python3.4/dist-packages/dataset/persistence/table.py", line 154, in update
    rp = self.database.executable.execute(stmt)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 1991, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/engine/base.py", line 1003, in _execute_clauseelement
    inline=len(distilled_params) > 1)
  File "<string>", line 1, in <lambda>
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/elements.py", line 494, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/elements.py", line 500, in _compiler
    return dialect.statement_compiler(dialect, self, **kw)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/compiler.py", line 395, in __init__
    Compiled.__init__(self, dialect, statement, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/compiler.py", line 190, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/compiler.py", line 213, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
    return meth(self, **kw)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/compiler.py", line 1958, in visit_update
    crud_params = crud._get_crud_params(self, update_stmt, **kw)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/crud.py", line 109, in _get_crud_params
    (", ".join("%s" % c for c in check))
sqlalchemy.exc.CompileError: Unconsumed column names: munAP_

https://github.com/DuckHunt-discord/DuckHunt-Discord/issues/8

I already tried to change the column name (it was munAP before) but it changed nothing !

What else can I try ? I suspect that the problem is in my code, but maybe it's dataset fault ?

Dave
  • 7,555
  • 8
  • 46
  • 88
WayToDoor
  • 1,180
  • 9
  • 24
  • 3
    I just encountered the same error. It was because I hadn't declared the column in my `table` call in sqlalchemy, so it's trying to find a column called "munAP_" and it's not finding it in the model. Use pdb to set a breakpoint at `/usr/local/lib/python3.4/dist-packages/dataset/persistence/table.py` lines 154 and 185, and see what the values are for `row` and `keys` and `stmt`. If you inspect those, you might be able to know what is happening. It might be a bug in `dataset`. – jadkik94 Nov 02 '16 at 19:39

0 Answers0