-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Bug Description
Users cannot create table columns whose names start with "index" (e.g., index, index_id, indexed_value) because the declaration parser misclassifies them as index declarations.
Root Cause
In src/datajoint/declare.py:373, the regex pattern used to detect index declarations is overly permissive:
elif re.match(r"^(unique\s+)?index\s*.*$", line, re.I): # index
compile_index(line, index_sql, adapter)This matches any line starting with "index", not just actual index declarations like index(col1, col2).
Steps to Reproduce
import datajoint as dj
schema = dj.Schema("test")
@schema
class MyTable(dj.Manual):
definition = """
index_id : int
---
index_value : float
"""This raises a DataJointError because index_id : int gets matched by the regex and routed to compile_index() instead of compile_attribute().
Affected Attribute Names
Any attribute starting with "index" (case-insensitive): index, index_id, indexed_value, INDEX_SOMETHING, etc.
Proposed Fix
Change the regex to require parentheses, matching only actual index declarations:
elif re.match(r"^(unique\s+)?index\s*\(.*\)$", line, re.I): # indexNote: compile_index() itself already uses a more restrictive regex that requires parentheses ((?P<unique>unique\s+)?index\s*\(\s*(?P<args>.*)\)), confirming this is the correct fix.
Existing Test
tests/integration/test_declare.py::test_regex_mismatch already documents this failure by expecting the error — it should be updated to expect success after the fix.