Question

My program got a strange problem, the exception stack is:

*except Exception, cause: raise ExprEvalError(src, cause)
ExprEvalError: date_after raises NameError: name 'date_after' is not defined*

so the code is:

    @staticmethod
def get_recently(days_before=30):
    delta = timedelta(days=days_before)
    date_after = datetime.now() - delta
    return list(Version.select(lambda v:v.create_time>date_after).order_by(desc(Version.create_time))[:])

The ORM framework is Pony,but I don't think it's relate to that.The code can run normally on other pc.

Could you tell me what is the problem? Thanks.

p.s.

  • Python-2.7.4
  • Pony-0.4.8
Was it helpful?

Solution 2

Your version of Pony is out of date. There is a closed bug regarding lamdbas in Pony that was resolved months ago, and it was the first (and only) hit for your error '"ExprEvalError" raises NameError: name is not defined' in Google.

Update your version of Pony and it should disappear.

OTHER TIPS

Pony ORM Author here. Lego Stormtroopr already answered the question how to fix the problem, but since you also want to know the reason of the bug, I'll describe it here. You can subscribe to our mailing list and ask any Pony-related questions there.

Short answer: In release 0.4.8 we improved @cut_traceback decorator and this change broke some unrelated functionality.

Detailed answer:

  1. In order to access the query parameter values (such as date_after in your code), Pony inspects the corresponding stack frame.
  2. Each Pony function which is part of public API wrapped with the @cut_traceback decorator. This decorator cuts out some internal traceback lines when Pony is used in a interactive mode. Earlier some user reported that the traceback output was too intimidate to them and @cut_traceback makes traceback output more "user-friendly".
  3. In previous versions of Pony @cut_traceback decorator had one shortcoming - it hid the real argument of the function and replaced them with *args and **kwargs. This may be annoying if an IDE shows function signature to the developer. Because of this, we replaced @cut_traceback decorator with the improved version, which keeps the signature of decorated function intact.
  4. But this new version of @cut_traceback decorator uses one more stack frame. Because of this, all Pony functions which take user parameters from the stack frame should be modified in order to inspect another stack frame. But we forgot to do it in the release 0.4.8
  5. In the release 0.4.9 we have fixed all functions which inspect stack frames and covered this functionality with tests.

Hope I answered your question :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top