dspy
dspy copied to clipboard
Bug: `AttributeError: 'NoneType' object has no attribute 'clear'`
I got this simple code:
question = "What is the capital of Japan?"
rag_with_assertions(question=question)
which throws this error AttributeError: 'NoneType' object has no attribute 'clear'
because of this line:
https://github.com/stanfordnlp/dspy/blob/98304a2eb9d1dddaaa846e30258cd5d8fc6b5d8d/dspy/primitives/assertions.py#L240
{
"name": "AttributeError",
"message": "'NoneType' object has no attribute 'clear'",
"stack": "---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 3
1 question = \"What is the capital of Japan?\"
----> 3 rag_with_assertions(question=question)
File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/program.py:29, in Module.__call__(self, *args, **kwargs)
28 def __call__(self, *args, **kwargs):
---> 29 return self.forward(*args, **kwargs)
File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/assertions.py:317, in handle_assert_forward.<locals>.forward(self, *args, **kwargs)
314 dspy.settings.configure(bypass_assert=args_to_vals[\"bypass_assert\"])
316 wrapped_forward = assertion_handler(self._forward, **handler_args)
--> 317 return wrapped_forward(*args, **kwargs)
File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/assertions.py:240, in backtrack_handler.<locals>.wrapper(*args, **kwargs)
238 else:
239 try:
--> 240 dsp.settings.trace.clear()
241 result = func(*args, **kwargs)
242 break
AttributeError: 'NoneType' object has no attribute 'clear'"
}
I believe assertions currently ask you to add a line at the top of your file.
dspy.configure(trace=[])
or something like that?
I had the same problem, and initializing the traces to an empty array as advised by @okhat worked. This bug can probably be closed.
@okhat your sollution worked for me too Thanks! ;), but may I ask where can I check this in doc or somewhere. Can u please point me into the right direction?