Skip to content

Commit b19910a

Browse files
committed
regex mismatch
1 parent 223ccdd commit b19910a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

datajoint/declare.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,10 @@ def format_attribute(attr):
443443
return f"`{attr}`"
444444
return f"({attr})"
445445

446-
try:
447-
match = re.match(
448-
r"(?P<unique>unique\s+)?index\s*\(\s*(?P<args>.*)\)", line, re.I
449-
).groupdict()
450-
except AttributeError:
446+
match = re.match(r"(?P<unique>unique\s+)?index\s*\(\s*(?P<args>.*)\)", line, re.I)
447+
if match is None:
451448
raise DataJointError(f'Table definition syntax error in line "{line}"')
449+
match = match.groupdict()
452450

453451
attr_list = re.findall(r"(?:[^,(]|\([^)]*\))+", match["args"])
454452
index_sql.append(

tests_old/test_declare.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,12 @@ class WithSuchALongPartNameThatItCrashesMySQL(dj.Part):
341341
definition = """
342342
-> (master)
343343
"""
344+
345+
@staticmethod
346+
@raises(dj.DataJointError)
347+
def test_regex_mismatch():
348+
@schema
349+
class IndexAttribute(dj.Manual):
350+
definition = """
351+
index: int
352+
"""

0 commit comments

Comments
 (0)