Entity NoneType does not belong to database when using to_dict #80

Closed
kasperhj opened this Issue Oct 2, 2014 · 1 comment

Projects

None yet

2 participants

@kasperhj
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)
to_dict(products)

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
@kozlovsky
Contributor

Thanks, should be fixed now

@kozlovsky kozlovsky added a commit that referenced this issue Oct 8, 2014
@kozlovsky kozlovsky Pony ORM Release Candidate 0.6rc1
http://blog.ponyorm.com/2014/10/08/pony-orm-0-6-release-candidate-1

# 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
395036b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment