Skip to content

Commit e339d46

Browse files
Merge pull request #1062 from ttngu207/populate_exclude_error_ignore
`.populate(reserve_jobs=True)` to exclude `error` and `ignore` keys
2 parents 7f6d76a + b3bb2a4 commit e339d46

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### 0.14.0 -- TBA
44
* Bugfix - Activating a schema requires all tables to exist even if `create_tables=False` PR [#1058](https://github.com/datajoint/datajoint-python/pull/1058)
5+
* Update - Populate call with `reserve_jobs=True` to exclude `error` and `ignore` keys - PR [#1062](https://github.com/datajoint/datajoint-python/pull/1062)
56

67
### 0.13.8 -- Sep 21, 2022
78
* Add - New documentation structure based on markdown PR [#1052](https://github.com/datajoint/datajoint-python/pull/1052)

datajoint/autopopulate.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import random
66
import inspect
77
from tqdm import tqdm
8+
from .hash import key_hash
89
from .expression import QueryExpression, AndList
910
from .errors import DataJointError, LostConnectionError
1011
import signal
@@ -202,6 +203,16 @@ def handler(signum, frame):
202203
old_handler = signal.signal(signal.SIGTERM, handler)
203204

204205
keys = (self._jobs_to_do(restrictions) - self.target).fetch("KEY", limit=limit)
206+
207+
# exclude "error" or "ignore" jobs
208+
if reserve_jobs:
209+
exclude_key_hashes = (
210+
jobs
211+
& {"table_name": self.target.table_name}
212+
& 'status in ("error", "ignore")'
213+
).fetch("key_hash")
214+
keys = [key for key in keys if key_hash(key) not in exclude_key_hashes]
215+
205216
if order == "reverse":
206217
keys.reverse()
207218
elif order == "random":

tests/test_autopopulate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ def test_populate(self):
5353
assert_true(self.ephys)
5454
assert_true(self.channel)
5555

56+
def test_populate_exclude_error_and_ignore_jobs(self):
57+
# test simple populate
58+
assert_true(self.subject, "root tables are empty")
59+
assert_false(self.experiment, "table already filled?")
60+
61+
keys = self.experiment.key_source.fetch("KEY", limit=2)
62+
for idx, key in enumerate(keys):
63+
schema.schema.jobs.insert1(
64+
{
65+
"table_name": self.experiment.table_name,
66+
"key_hash": dj.hash.key_hash(key),
67+
"status": "error" if idx == 0 else "ignore",
68+
"key": key,
69+
}
70+
)
71+
72+
self.experiment.populate(reserve_jobs=True)
73+
assert_equal(
74+
len(self.experiment.key_source & self.experiment),
75+
len(self.experiment.key_source) - 2,
76+
)
77+
5678
def test_allow_direct_insert(self):
5779
assert_true(self.subject, "root tables are empty")
5880
key = self.subject.fetch("KEY", limit=1)[0]

0 commit comments

Comments
 (0)