Skip to content

Commit 3451149

Browse files
Merge pull request #1188 from datajoint/patch-1180
Disable hidden timestamp attribute by default
2 parents 07338fa + 23d9579 commit 3451149

File tree

4 files changed

+71
-21
lines changed

4 files changed

+71
-21
lines changed

CHANGELOG.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
## Release notes
22

3-
### 0.14.3 -- Sep 20, 2024
4-
- Added - `dj.Top` restriction ([#1024](https://github.com/datajoint/datajoint-python/issues/1024)) PR [#1084](https://github.com/datajoint/datajoint-python/pull/1084)
3+
### 0.14.3 -- Sep 23, 2024
4+
- Added - `dj.Top` restriction - PR [#1024](https://github.com/datajoint/datajoint-python/issues/1024)) PR [#1084](https://github.com/datajoint/datajoint-python/pull/1084)
55
- Fixed - Added encapsulating double quotes to comply with [DOT language](https://graphviz.org/doc/info/lang.html) - PR [#1177](https://github.com/datajoint/datajoint-python/pull/1177)
6-
- Added - Datajoint python CLI ([#940](https://github.com/datajoint/datajoint-python/issues/940)) PR [#1095](https://github.com/datajoint/datajoint-python/pull/1095)
6+
- Added - Datajoint python CLI ([#940](https://github.com/datajoint/datajoint-python/issues/940)) - PR [#1095](https://github.com/datajoint/datajoint-python/pull/1095)
77
- Added - Ability to set hidden attributes on a table - PR [#1091](https://github.com/datajoint/datajoint-python/pull/1091)
88
- Added - Ability to specify a list of keys to populate - PR [#989](https://github.com/datajoint/datajoint-python/pull/989)
9-
- Fixed - fixed topological sort [#1057](https://github.com/datajoint/datajoint-python/issues/1057)- PR [#1184](https://github.com/datajoint/datajoint-python/pull/1184)
10-
- Fixed - .parts() not always returning parts [#1103](https://github.com/datajoint/datajoint-python/issues/1103)- PR [#1184](https://github.com/datajoint/datajoint-python/pull/1184)
11-
- Changed - replace `setup.py` with `pyproject.toml` PR [#1183](https://github.com/datajoint/datajoint-python/pull/1183)
9+
- Fixed - fixed topological sort [#1057](https://github.com/datajoint/datajoint-python/issues/1057) - PR [#1184](https://github.com/datajoint/datajoint-python/pull/1184)
10+
- Fixed - .parts() not always returning parts [#1103](https://github.com/datajoint/datajoint-python/issues/1103) - PR [#1184](https://github.com/datajoint/datajoint-python/pull/1184)
11+
- Changed - replace `setup.py` with `pyproject.toml` - PR [#1183](https://github.com/datajoint/datajoint-python/pull/1183)
12+
- Changed - disable `add_hidden_timestamp` configuration option by default - PR [#1188](https://github.com/datajoint/datajoint-python/pull/1188)
1213

1314
### 0.14.2 -- Aug 19, 2024
1415
- Added - Migrate nosetests to pytest - PR [#1142](https://github.com/datajoint/datajoint-python/pull/1142)

datajoint/declare.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .errors import DataJointError, _support_filepath_types, FILEPATH_FEATURE_SWITCH
1111
from .attribute_adapter import get_adapter
1212
from .condition import translate_attribute
13+
from .settings import config
1314

1415
UUID_DATA_TYPE = "binary(16)"
1516
MAX_TABLE_NAME_LENGTH = 64
@@ -311,17 +312,18 @@ def declare(full_table_name, definition, context):
311312
external_stores,
312313
) = prepare_declare(definition, context)
313314

314-
metadata_attr_sql = [
315-
"`_{full_table_name}_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"
316-
]
317-
attribute_sql.extend(
318-
attr.format(
319-
full_table_name=sha1(
320-
full_table_name.replace("`", "").encode("utf-8")
321-
).hexdigest()
315+
if config.get("add_hidden_timestamp", False):
316+
metadata_attr_sql = [
317+
"`_{full_table_name}_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP"
318+
]
319+
attribute_sql.extend(
320+
attr.format(
321+
full_table_name=sha1(
322+
full_table_name.replace("`", "").encode("utf-8")
323+
).hexdigest()
324+
)
325+
for attr in metadata_attr_sql
322326
)
323-
for attr in metadata_attr_sql
324-
)
325327

326328
if not primary_key:
327329
raise DataJointError("Table must have a primary key")

datajoint/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"display.show_tuple_count": True,
4848
"database.use_tls": None,
4949
"enable_python_native_blobs": True, # python-native/dj0 encoding support
50+
"add_hidden_timestamp": False,
5051
"filepath_checksum_size_limit": None, # file size limit for when to disable checksums
5152
}
5253
)

tests/test_declare.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
import datajoint as dj
44
import inspect
55
from datajoint.declare import declare
6+
from datajoint.settings import config
7+
8+
9+
@pytest.fixture(scope="function")
10+
def enable_add_hidden_timestamp():
11+
orig_config_val = config.get("add_hidden_timestamp")
12+
config["add_hidden_timestamp"] = True
13+
yield
14+
if orig_config_val is not None:
15+
config["add_hidden_timestamp"] = orig_config_val
16+
17+
18+
@pytest.fixture(scope="function")
19+
def disable_add_hidden_timestamp():
20+
orig_config_val = config.get("add_hidden_timestamp")
21+
config["add_hidden_timestamp"] = False
22+
yield
23+
if orig_config_val is not None:
24+
config["add_hidden_timestamp"] = orig_config_val
625

726

827
def test_schema_decorator(schema_any):
@@ -373,9 +392,36 @@ class Table_With_Underscores(dj.Manual):
373392
schema_any(Table_With_Underscores)
374393

375394

376-
def test_hidden_attributes(schema_any):
395+
def test_add_hidden_timestamp_default_value():
396+
config_val = config.get("add_hidden_timestamp")
377397
assert (
378-
list(Experiment().heading._attributes.keys())[-1].split("_")[2] == "timestamp"
379-
)
380-
assert any(a.is_hidden for a in Experiment().heading._attributes.values())
381-
assert not any(a.is_hidden for a in Experiment().heading.attributes.values())
398+
config_val is not None and not config_val
399+
), "Default value for add_hidden_timestamp is not False"
400+
401+
402+
def test_add_hidden_timestamp_enabled(enable_add_hidden_timestamp, schema_any):
403+
assert config["add_hidden_timestamp"], "add_hidden_timestamp is not enabled"
404+
msg = f"{Experiment().heading._attributes=}"
405+
assert any(
406+
a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values()
407+
), msg
408+
assert any(
409+
a.name.startswith("_") for a in Experiment().heading._attributes.values()
410+
), msg
411+
assert any(a.is_hidden for a in Experiment().heading._attributes.values()), msg
412+
assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg
413+
414+
415+
def test_add_hidden_timestamp_disabled(disable_add_hidden_timestamp, schema_any):
416+
assert not config[
417+
"add_hidden_timestamp"
418+
], "expected add_hidden_timestamp to be False"
419+
msg = f"{Experiment().heading._attributes=}"
420+
assert not any(
421+
a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values()
422+
), msg
423+
assert not any(
424+
a.name.startswith("_") for a in Experiment().heading._attributes.values()
425+
), msg
426+
assert not any(a.is_hidden for a in Experiment().heading._attributes.values()), msg
427+
assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg

0 commit comments

Comments
 (0)