Skip to content

Commit 003f0d5

Browse files
docs: Document make_kwargs passed to make_fetch in tripartite pattern (#146)
Update tripartite pattern examples to show that make_fetch receives **kwargs from populate(make_kwargs={...}). Related to datajoint-python#1350, datajoint-python#1361.
1 parent 783ced6 commit 003f0d5

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/explanation/computation-model.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ class SignalAverage(dj.Computed):
207207
avg_signal : float64
208208
"""
209209

210-
def make_fetch(self, key):
211-
"""Step 1: Fetch input data (outside transaction)"""
210+
def make_fetch(self, key, **kwargs):
211+
"""Step 1: Fetch input data (outside transaction).
212+
213+
kwargs are passed from populate(make_kwargs={...}).
214+
"""
212215
raw_signal = (RawSignal & key).fetch1("signal")
213216
return (raw_signal,)
214217

src/how-to/run-computations.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ class LongComputation(dj.Computed):
199199
result : float64
200200
"""
201201

202-
def make_fetch(self, key):
203-
"""Fetch input data (outside transaction)"""
202+
def make_fetch(self, key, **kwargs):
203+
"""Fetch input data (outside transaction).
204+
205+
kwargs are passed from populate(make_kwargs={...}).
206+
"""
204207
data = (RawData & key).fetch1('data')
205208
return (data,)
206209

src/reference/specs/autopopulate.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ class HeavyComputation(dj.Computed):
334334
result : <blob>
335335
"""
336336

337-
def make_fetch(self, key):
338-
"""Fetch all required data (runs in transaction)."""
337+
def make_fetch(self, key, **kwargs):
338+
"""Fetch all required data (runs in transaction).
339+
340+
kwargs are passed from populate(make_kwargs={...}).
341+
"""
339342
return (Recording & key).fetch1('raw_data')
340343

341344
def make_compute(self, key, data):
@@ -393,6 +396,15 @@ class ConfigurableAnalysis(dj.Computed):
393396
ConfigurableAnalysis.populate(make_kwargs={'threshold': 0.8})
394397
```
395398

399+
**Tripartite pattern:** When using the method-based tripartite pattern, `make_kwargs` are passed to `make_fetch()`:
400+
401+
```python
402+
def make_fetch(self, key, verbose=False, **kwargs):
403+
if verbose:
404+
print(f"Fetching {key}")
405+
return (Source & key).fetch1('data')
406+
```
407+
396408
**Anti-pattern warning:** Passing arguments that affect the computed result breaks reproducibility—all inputs should come from `fetch` calls inside `make()`. If a parameter affects results, it should be stored in a lookup table and referenced via foreign key.
397409

398410
**Acceptable use:** Directives that don't affect results, such as:
@@ -973,8 +985,8 @@ def make(self, key):
973985
yield # Re-acquire transaction
974986
self.insert1({**key, 'result': result})
975987

976-
# Tripartite (methods)
977-
def make_fetch(self, key): return data
988+
# Tripartite (methods) - kwargs passed to make_fetch
989+
def make_fetch(self, key, **kwargs): return data
978990
def make_compute(self, key, data): return result
979991
def make_insert(self, key, result): self.insert1(...)
980992
```

0 commit comments

Comments
 (0)