[PonyORM-list] show() not printing LongStr (Alexey Malashkevich)

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Wed Dec 10 22:44:27 UTC 2014


Hi Chris!

This behavior is "by design". The LongStr type is intended for very long
strings, such as the description of a product or the content of an article.
We typically don't want to load such an attribute each time the object
itself is loaded. Hence, LongStr attributes marked as "lazy" by default.

The `show()` method of the query result does not display lazy attributes.
Firstly, because such attributes are not loaded by default, and we don't
want to send additional queries. And secondly, because the content of such
attribute can be really large for displaying inside formatted table cell.

If you truly want to display such an attribute, you have several options:

1) You can use `str` type instead of `LongStr` if the content of the
attribute is not really large.

2) You can mark attribute as a non-lazy, if you want to load it with the
typical query:

    attr1 = Required(LongStr, lazy=False)

Currently it is not possible to force the query to load lazy attributes
along with the normal attributes. In the future we plan to add the way to
explicitly load some lazy attributes with the query. After that the
`show()` method probably should display such attributes along with the
other attributes.

Regards,
Alexander Kozlovsky


On Wed, Dec 10, 2014 at 10:56 PM, Chris Wood <c.c.wood at gmail.com> wrote:

> Hi Alexey,
>
> thanks for the reply; I should have been clearer about when I was
> calling show()! I was trying to call it to show what data was in a
> table in my database:
>
> >>> from pony.orm import *
> >>> db = Database()
> >>> class Entity1(db.Entity):
> ...   attr1 = Required(LongStr)
> ...
> >>> db.bind('sqlite',':memory:')
> >>> db.generate_mapping(create_tables=True)
> >>> show(E1)
> class E1(Entity1):
>     id = PrimaryKey(int, auto=True)
>     attr1 = Required(LongStr)
> >>> test_data_entry = Entity1(attr1="test!")
> >>> data = select(p for p in Entity1)[:]
> >>> data.show()
> id
> --
> 1
>
> compared with
>
> >>> from pony.orm import *
> >>> db = Database()
> >>> class Entity2(db.Entity):
> ...   attr2 = Required(str)
> ...
> >>> db.bind('sqlite',':memory:')
> >>> db.generate_mapping(create_tables=True)
> >>> show(Entity2)
> class Entity2(Entity):
>     id = PrimaryKey(int, auto=True)
>     attr1 = Required(str)
> >>> test_data_entry= Entity2(attr2="test!")
> >>> data = select(p for p in Entity2)[:]
> >>> data.show()
> id|attr2
> --+-----
> 1 |test!
>
>
> It seems that the column which is defined as a LongStr isn't
> displayed, but one that is displayed as a str is?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141211/d4d30491/attachment.html>


More information about the ponyorm-list mailing list