Fix a bug with Flat.from_dict

This commit is contained in:
Lucas Verney 2017-12-06 19:03:25 +01:00
parent 03d2ad6f7f
commit 0376cdf4e0

View File

@ -11,7 +11,7 @@ import arrow
import enum import enum
from sqlalchemy import ( from sqlalchemy import (
Column, DateTime, Enum, Float, SmallInteger, String, Text Column, DateTime, Enum, Float, SmallInteger, String, Text, inspect
) )
from sqlalchemy.orm import validates from sqlalchemy.orm import validates
@ -175,11 +175,9 @@ class Flat(BASE):
) )
del flat_dict["flatisfy"] del flat_dict["flatisfy"]
flat_object = Flat() flat_dict = {k: v for k, v in flat_dict.items()
# Using a __dict__.update() call to make it work even if there are if k in inspect(Flat).columns.keys()}
# extra keys in flat_dict which are not valid kwargs for Flat model. return Flat(**flat_dict)
flat_object.__dict__.update(flat_dict)
return flat_object
def __repr__(self): def __repr__(self):
return "<Flat(id=%s, urls=%s)>" % (self.id, self.urls) return "<Flat(id=%s, urls=%s)>" % (self.id, self.urls)