[PonyORM-list] Error on wrong line

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Mon Oct 27 18:52:53 UTC 2014

Hi Arthur!

Good point about documentation, I think we should change it as you said.

Regarding the exception, this is the standard Python behavior. Consider
this example:

x = 10
def func():
    x = 5


If you run this example, you'll get the exception "UnboundLocalError: local
variable 'x' referenced before assignment" in the first line of the
function. This is because when Python parses the program text, it sees "x =
5" assignment and assumes that the x is a local name. It then uses name x
as a local name during all function body, even before "x = 5" line. You
cannot use name x as a global name in the beginning of the function and as
a local name in the end.

See for example:


On Mon, Oct 27, 2014 at 9:27 PM, Goldberg, Arthur P <
arthur.p.goldberg at mssm.edu> wrote:

>  Hi guys
>   Generally, pony has been great. Thanks!
>  However I think this is a bug. I ran the attached program, and it
> generates this call stack. The error is reported in line 202 but it is
> actually in line 203.  I know that the ID in 203 overrides the db.entity
> class of that name, but I would think that the error does not exist until
> line 203.
>  Traceback (most recent call last):
>   File "../geneticsSubjects.py", line 212, in <module>
>     dumpIDs()
>   File "<auto generated wrapper of dumpIDs() function>", line 2, in dumpIDs
>   File
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pony/orm/core.py",
> line 345, in new_func
>     try: return func(*args, **kwargs)
>   File "../geneticsSubjects.py", line 202, in dumpIDs
>     print( ID.__header__() )
> UnboundLocalError: local variable 'ID' referenced before assignment
>   Also, I have a documentation suggestion.for example, your documentation
>  says:
> for p in select(p for p in Product):
>     print p.name, p.price
>   whereas it  is more convenient to say:
>  for p in Product.select():
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.org
> /ponyorm-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141027/e3a5b0a6/attachment-0001.html>

More information about the ponyorm-list mailing list