elijahbenizzy opened a new issue, #268:
URL: https://github.com/apache/burr/issues/268

   **Is your feature request related to a problem? Please describe.**
   
   There are cases in which you only want to write one thing to state. Take, 
for example, this:
   
   ```python
   @action(reads=["prompt"], writes=["response", "error"])
   def respond(state: State) -> State:
       try:
           return state.update(response=_query(state["prompt"]))
       except SpecificException as e:
           return state.update(error=e)
   ```
   
   Currently this would break in both cases with the following error:
   
   ```bash
   File 
[~/dev/dagworks/os/burr/burr/core/application.py:155](http://localhost:8888/lab/workspaces/auto-3/tree/~/dev/dagworks/os/burr/burr/core/application.py#line=154),
 in _validate_reducer_writes(reducer, state, name)
       153 missing_writes = set(reducer.writes) - state.keys()
       154 if len(missing_writes) > 0:
   --> 155     raise ValueError(
       156         f"State is missing write keys after running: {name}. Missing 
keys are: {missing_writes}. "
       157         f"Has writes: {required_writes}"
       158     )
   
   ValueError: State is missing write keys after running: respond. Missing keys 
are: {'response'}. Has writes: ['response', 'error']`
   ```
   
   
   **Describe the solution you'd like**
   In most cases, people will end up padding with `None`, or some other 
sentinel value. What if we made it a specific exception?
   
   ```python
   @action(reads=["prompt"], writes=["response", "error"], 
default_writes={"response" : None, "error" : None})
   def respond(state: State) -> State:
       try:
           return state.update(response=_query(state["prompt"]))
       except SpecificException as e:
           return state.update(error=e)
   ```
   
   **Describe alternatives you've considered**
   We could leverage the typing system with Optional see #139, or not enable 
this. That said, I think this is a fairly simple pattern. 
   
   Other Q is how to specify that just one of these is required. Tooling like 
pydantic requires custom validation for this, which feels a little overboard... 
Defaults is a nice but clean way to do this I think.
   
   **Additional context**
   
   Based on this discord question: 
https://discord.com/channels/1221891403253288970/1221892061842772018/1260680704002494514.
 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to