param.depends(on_init=True) does not execute without watch=True
- Dominant language
- Python
- Stars
- 521
- Forks
- 86
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 35
Description
Using the param.depends decorator in a param.Parameterized class with on_init=True does not execute without also setting watch=True.
#### ALL software version info
python 3.11.1
param 1.12.3
run in jupyter notebook within VS Code
Version: 1.75.1 (user setup)
Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Date: 2023-02-08T21:32:34.589Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Windows_NT x64 10.0.19045
Sandboxed: No
#### Description of expected behavior and the observed behavior
expected behaviour would be that a function with decorator "@param.depends(on_init=True)" would execute on init without extra call or setting watch=True.
#### Complete, minimal, self-contained example code that reproduces the issue
```
import param
class Oninit(param.Parameterized):
a = param.String(default="not initialised")
def __init__(self, **params):
super().__init__(**params)
print("Oninit, __init__, 1: ", self.a)
# Calling the fn directly works:
# self.dosomethingoninit()
print("Oninit, __init__, 2: ", self.a)
return
# That decorator leads to a function call:
# @param.depends(watch=True, on_init=True)
# That decorator doesn't execute:
@param.depends(on_init=True)
def dosomethingoninit(self):
print("Oninit, dosomethingoninit, 1: ", self.a)
self.a = "did something"
print("Oninit, dosomethingoninit, 2: ", self.a)
return
oi = Oninit()
```
#### Stack traceback and/or browser JavaScript console output
``` @param.depends(on_init=True) ``` results in:
```
Oninit, __init__, 1: not initialised
Oninit, __init__, 2: not initialised
```
``` @param.depends(watch=True, on_init=True) ``` results in:
```
Oninit, dosomethingoninit, 1: not initialised
Oninit, dosomethingoninit, 2: did something
Oninit, __init__, 1: did something
Oninit, __init__, 2: did something
```
calling function directly inside __init() results in:
```
Oninit, __init__, 1: not initialised
Oninit, dosomethingoninit, 1: not initialised
Oninit, dosomethingoninit, 2: did something
Oninit, __init__, 2: did something
```
#### Screenshots or screencasts of the bug in action
Contributor guide
Assessment
This issue has not been assessed yet.