From 80d56453a505aafaeb6fb63263cfac82271db487 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 7 Apr 2016 09:46:01 -0400 Subject: [PATCH] Fixing bug with primary key reuse by SQLAlchemy This change fixes a bug with the Pie object table definitions used by SQLAlchemy to store managed objects and attributes for the PyKMIP software server. While primary keys are specified for all tables, they do not by default auto-increment with SQLAlchemy/SQLite, causing collisions and uniqueness constraint violations when bulk testing with the server. Add an explicit SQLite auto-increment tag to each table prevents this from happening. --- kmip/pie/objects.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kmip/pie/objects.py b/kmip/pie/objects.py index e97b9d4..82c59b0 100644 --- a/kmip/pie/objects.py +++ b/kmip/pie/objects.py @@ -57,6 +57,9 @@ class ManagedObject(sql.Base): 'polymorphic_identity': 'ManagedObject', 'polymorphic_on': _class_type } + __table_args__ = { + 'sqlite_autoincrement': True + } @abstractmethod def __init__(self): @@ -152,6 +155,9 @@ class CryptographicObject(ManagedObject): __mapper_args__ = { 'polymorphic_identity': 'CryptographicObject' } + __table_args__ = { + 'sqlite_autoincrement': True + } @abstractmethod def __init__(self): @@ -212,6 +218,9 @@ class Key(CryptographicObject): __mapper_args__ = { 'polymorphic_identity': 'Key' } + __table_args__ = { + 'sqlite_autoincrement': True + } @abstractmethod def __init__(self): @@ -259,6 +268,9 @@ class SymmetricKey(Key): __mapper_args__ = { 'polymorphic_identity': 'SymmetricKey' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, algorithm, length, value, masks=None, name='Symmetric Key'): @@ -397,6 +409,9 @@ class PublicKey(Key): __mapper_args__ = { 'polymorphic_identity': 'PublicKey' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, algorithm, length, value, format_type=enums.KeyFormatType.X_509, masks=None, @@ -548,6 +563,9 @@ class PrivateKey(Key): __mapper_args__ = { 'polymorphic_identity': 'PrivateKey' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, algorithm, length, value, format_type, masks=None, name='Private Key'): @@ -696,6 +714,9 @@ class Certificate(CryptographicObject): __mapper_args__ = { 'polymorphic_identity': 'Certificate' } + __table_args__ = { + 'sqlite_autoincrement': True + } @abstractmethod def __init__(self, certificate_type, value, masks=None, @@ -793,6 +814,9 @@ class X509Certificate(Certificate): __mapper_args__ = { 'polymorphic_identity': 'Certificate' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, value, masks=None, name='X.509 Certificate'): """ @@ -866,6 +890,9 @@ class SecretData(CryptographicObject): __mapper_args__ = { 'polymorphic_identity': 'SecretData' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, value, data_type, masks=None, name='Secret Data'): """ @@ -979,6 +1006,9 @@ class OpaqueObject(ManagedObject): __mapper_args__ = { 'polymorphic_identity': 'OpaqueData' } + __table_args__ = { + 'sqlite_autoincrement': True + } def __init__(self, value, opaque_type, name='Opaque Object'): """