Skip to content

Commit 717d4b5

Browse files
committed
hash table name for hidden attrs
1 parent b1019f4 commit 717d4b5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

datajoint/declare.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import pyparsing as pp
77
import logging
8+
from hashlib import sha1
89
from .errors import DataJointError, _support_filepath_types, FILEPATH_FEATURE_SWITCH
910
from .attribute_adapter import get_adapter
1011
from .condition import translate_attribute
@@ -19,7 +20,6 @@
1920
METADATA_ATTRIBUTES_SQL = [
2021
"`_{full_table_name}_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"
2122
]
22-
LONGEST_METADATA_ATTRIBUTE = len("__timestamp")
2323

2424
TYPE_PATTERN = {
2525
k: re.compile(v, re.I)
@@ -315,9 +315,9 @@ def declare(full_table_name, definition, context):
315315
attribute_sql.extend(
316316
[
317317
attr.format(
318-
full_table_name=full_table_name.replace("`", "")[
319-
0 : 64 - LONGEST_METADATA_ATTRIBUTE
320-
]
318+
full_table_name=sha1(
319+
full_table_name.replace("`", "").encode("utf-8")
320+
).hexdigest()
321321
)
322322
for attr in METADATA_ATTRIBUTES_SQL
323323
]

tests_old/test_declare.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,14 @@ class WithSuchALongPartNameThatItCrashesMySQL(dj.Part):
345345
@staticmethod
346346
def test_hidden_attributes():
347347
assert (
348-
list(Experiment().heading._attributes.keys())[-1]
349-
== "_djtest_test1._experiment_timestamp"
348+
list(Experiment().heading._attributes.keys())[-1].split("_")[2]
349+
== "timestamp"
350350
)
351351
assert (
352-
list(Experiment().heading.attributes.keys())[-1]
353-
!= "_djtest_test1._experiment_timestamp"
352+
len([a for a in Experiment().heading._attributes.values() if a.is_hidden])
353+
!= 0
354+
)
355+
assert (
356+
len([a for a in Experiment().heading.attributes.values() if a.is_hidden])
357+
== 0
354358
)

0 commit comments

Comments
 (0)