Skip to content

Commit 5649c98

Browse files
committed
shorten attr name if too long
1 parent 0d89af2 commit 5649c98

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

datajoint/declare.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,11 @@ def declare(full_table_name, definition, context):
296296
:param context: dictionary of objects that might be referred to in the table
297297
:return: SQL CREATE TABLE statement, list of external stores used
298298
"""
299-
if (
300-
len(full_table_name.replace("`", "")) + LONGEST_METADATA_ATTRIBUTE
301-
> MAX_TABLE_NAME_LENGTH
302-
):
299+
table_name = full_table_name.strip("`").split(".")[1]
300+
if len(table_name) > MAX_TABLE_NAME_LENGTH:
303301
raise DataJointError(
304302
"Table name `{name}` exceeds the max length of {max_length}".format(
305-
name=full_table_name.replace("`", ""),
306-
max_length=MAX_TABLE_NAME_LENGTH - LONGEST_METADATA_ATTRIBUTE,
303+
name=table_name, max_length=MAX_TABLE_NAME_LENGTH
307304
)
308305
)
309306

@@ -317,7 +314,11 @@ def declare(full_table_name, definition, context):
317314
) = prepare_declare(definition, context)
318315
attribute_sql.extend(
319316
[
320-
attr.format(full_table_name=full_table_name.replace("`", ""))
317+
attr.format(
318+
full_table_name=full_table_name.replace("`", "")[
319+
0 : 64 - LONGEST_METADATA_ATTRIBUTE
320+
]
321+
)
321322
for attr in METADATA_ATTRIBUTES_SQL
322323
]
323324
)

0 commit comments

Comments
 (0)