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 NoneType does not belong to database when using to_dict #80

kasperhj opened this Issue Oct 2, 2014 · 1 comment


None yet
2 participants
Copy link

kasperhj commented Oct 2, 2014

I'm having an issue with the to_dict() and Entity.to_dict().

Consider the following:

class Product(db.Entity):
    id = Required(int)
    discount = Optional("Discount")

class Discount(db.Entity):
    value = Required(int)
    products = Set("Product")

Then with

products = select(p for p in Product)

I get

TypeError: Entity NoneType does not belong to database <pony.orm.core.Database object at 0x0000000002E43518>

which, I guess is caused by the None values of the discount if there is no discount for the product.
It's the same problem if I iterate through the meals and call meal.to_dict().

@kozlovsky kozlovsky added the bug label Oct 3, 2014

@kozlovsky kozlovsky self-assigned this Oct 3, 2014

@kozlovsky kozlovsky closed this in b4ce187 Oct 3, 2014


This comment has been minimized.

Copy link

kozlovsky commented Oct 3, 2014

Thanks, should be fixed now

kozlovsky added a commit that referenced this issue Oct 8, 2014

Pony ORM Release Candidate 0.6rc1

# New features:

* Python 3 support
* pymysql adapter support for MySQL databases

# Backward incompatible changes

Now Pony treats both `str`` and `unicode`` attribute types as they are unicode strings in both Python 2 and 3. So, the attribute declaration `attr = Required(str)` is equal to `attr = Required(unicode)` in Python 2 and 3. The same thing is with `LongStr` and `LongUnicode` - both of them are represented as unicode strings now.

For the sake of backward compatibility Pony adds `unicode` as an alias to `str` and `buffer` as an alias to `bytes` in Python 3.

# Other changes and bug fixes

* Fixes #74: Wrong FK column type when using sql_type on foreign ID column
* Fixes #75: MappingError for self-referenced entities in a many-to-many relationship
* Fixes #80: “Entity NoneType does not belong to database” when using to_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment