New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity.select_random() AssertionError #142

angru opened this Issue Sep 4, 2015 · 2 comments


None yet
2 participants

angru commented Sep 4, 2015

from pony.orm import Database, Required, PrimaryKey, db_session, show, select

db = Database()

class Some(db.Entity):
    id = PrimaryKey(int, auto=True)
    value = Required(int)

if __name__ == '__main__':
    db.bind('sqlite', ':memory:')

    with db_session:
        for i in range(10):
            s = Some(value=i)

        show(Some.select_random(limit=1))  # works fine here

    with db_session:
        show(Some.select_random(limit=1))  # error here if Entity is not "warmed"
Traceback (most recent call last):
  File "D:\projects\Python\quotebot\", line 24, in <module>
  File "<string>", line 2, in select_random
  File "C:\dev\Python34\lib\site-packages\pony\", line 88, in cut_traceback
    return func(*args, **kwargs)
  File "C:\dev\Python34\lib\site-packages\pony\orm\", line 3015, in select_random
    arguments = adapter([ (id,) for id in ids ])
  File "C:\dev\Python34\lib\site-packages\pony\orm\", line 161, in adapter
    return tuple(convert(values, params))
  File "C:\dev\Python34\lib\site-packages\pony\orm\", line 137, in convert
    assert type(type(value)).__name__ == 'EntityMeta'

But it works fine after we "warm up" Entity like:

    with db_session:
        show(select(s for s in Some))

@kozlovsky kozlovsky closed this in a4784aa Sep 4, 2015

@kozlovsky kozlovsky added this to the 0.6.2 milestone Sep 4, 2015

@kozlovsky kozlovsky added the bug label Sep 4, 2015

@kozlovsky kozlovsky self-assigned this Sep 4, 2015


This comment has been minimized.

Show comment
Hide comment

kozlovsky Sep 4, 2015


Thanks, fixed!


kozlovsky commented Sep 4, 2015

Thanks, fixed!


This comment has been minimized.

Show comment
Hide comment

angru Sep 4, 2015

wow, fixed so quickly, thanks.

angru commented Sep 4, 2015

wow, fixed so quickly, thanks.

kozlovsky added a commit that referenced this issue Jan 11, 2016

Pony ORM Release 0.6.2 (2015-01-11)
The documentation was moved from this repo to a separate one at
The compiled version can be found at

# New features

* Python 3.5 support
* #132, #145: raw_sql() function was added
* #126: Ability to use @db_session with generator functions
* #116: Add support to select by UUID
* Ability to get string SQL statement using the Query.get_sql() method
* New function delete(gen) and Query.delete(bulk=False)
* Now it is possible to override Entity.__init__() and declare custom entity methods

# Backward incompatible changes

* Normalizing table names for symmetric relationships
* Autostrip - automatically remove leading and trailing characters

# Bugfixes

* #87: Pony fails with pymysql installed as MySQLdb
* #118: Pony should reconnect if previous connection was created before process was forked
* #121: Unable to update value of unique attribute
* #122: AssertionError when changing part of a composite key
* #127: a workaround for incorrect pysqlite locking behavior
* #136: Cascade delete does not work correctly for one-to-one relationships
* #141, #143: remove restriction on adding new methods to entities
* #142: Entity.select_random() AssertionError
* #147: Add 'atom_expr' symbol handling for Python 3.5 grammar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment