Skip to content

Commit 79acd70

Browse files
Fix crash related to non existent primary key
1 parent d438ecc commit 79acd70

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

pymysqlreplication/column.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def __parse_column_definition(self, column_type, column_schema, packet):
2424
self.data["comment"] = column_schema["COLUMN_COMMENT"]
2525
self.data["unsigned"] = False
2626
self.data["type_is_bool"] = False
27-
self.data["is_primary"] = column_schema["COLUMN_KEY"] == "PRI"
27+
if "COLUMN_KEY" in column_schema and column_schema["COLUMN_KEY"] == "PRI":
28+
self.data["is_primary"] = True
29+
else:
30+
self.data["is_primary"] = False
2831

2932
if column_schema["COLUMN_TYPE"].find("unsigned") != -1:
3033
self.data["unsigned"] = True

pymysqlreplication/table.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33

44
class Table(object):
5-
def __init__(self, column_schemas, table_id, schema, table, columns):
6-
primary_key = [c.data["name"] for c in columns if c.data["is_primary"]]
7-
if len(primary_key) == 0:
8-
primary_key = ''
9-
elif len(primary_key) == 1:
10-
primary_key, = primary_key
11-
else:
12-
primary_key = tuple(primary_key)
5+
def __init__(self, column_schemas, table_id, schema, table, columns, primary_key = None):
6+
if primary_key is None:
7+
primary_key = [c.data["name"] for c in columns if c.data["is_primary"]]
8+
if len(primary_key) == 0:
9+
primary_key = ''
10+
elif len(primary_key) == 1:
11+
primary_key, = primary_key
12+
else:
13+
primary_key = tuple(primary_key)
1314

1415
self.data = {
1516
"column_schemas": column_schemas,

0 commit comments

Comments
 (0)