dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Bug: `AttributeError: 'NoneType' object has no attribute 'clear'`

Open younes-io opened this issue 11 months ago • 1 comments

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'"
}

younes-io avatar Mar 02 '24 14:03 younes-io

I believe assertions currently ask you to add a line at the top of your file.

dspy.configure(trace=[])

or something like that?

okhat avatar Mar 02 '24 17:03 okhat

I had the same problem, and initializing the traces to an empty array as advised by @okhat worked. This bug can probably be closed.

sleeper avatar Mar 29 '24 11:03 sleeper

@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?

fireking77 avatar Apr 11 '24 08:04 fireking77