Don't set autoincrement for ids with zeroes. Test included. #580

This commit is contained in:
Petr Viktorin 2011-04-19 12:24:40 +03:00
parent 98dcc613e2
commit 7d7fcc74c8
2 changed files with 19 additions and 2 deletions

View file

@ -923,7 +923,7 @@ class MoveMetaCategory(TableBase):
u"""Very general categories that loosely group move effects."""
__tablename__ = 'move_meta_categories'
__singlename__ = 'move_meta_category'
id = Column(Integer, primary_key=True, nullable=False,
id = Column(Integer, primary_key=True, nullable=False, autoincrement=False,
info=dict(description="A numeric ID"))
identifier = Column(Unicode(32), nullable=False, index=True, unique=True,
info=dict(description="An identifier", format='identifier'))

View file

@ -1,8 +1,9 @@
from nose.tools import *
import unittest
from sqlalchemy.orm import aliased
from sqlalchemy.orm.exc import NoResultFound
from pokedex.db import connect, tables
from pokedex.db import connect, tables, util
def test_encounter_slots():
# Encounters have a version, which has a version group; encounters also
@ -22,3 +23,19 @@ def test_encounter_slots():
assert_equal(sanity_q.count(), 0,
"Encounter slots all match the encounters they belong to")
def test_nonzero_autoincrement_ids():
"""Check that autoincrementing ids don't contain zeroes
MySQL doesn't like these, see e.g. bug #580
"""
session = connect()
for cls in tables.mapped_classes:
if 'id' in cls.__table__.c:
if cls.__table__.c.id.autoincrement:
@raises(NoResultFound)
def nonzero_id(cls):
util.get(session, cls, id=0)
nonzero_id.description = "No zero id in %s" % cls.__name__
yield nonzero_id, cls