I'm trying to delete an attribute from model object that is created on the go, but there seems to be some problem doing so. So, far I've searched through every place including SQLAlchemy documentation and some of its code to find a potential fix but unable to find one.
Below code works fine on python classes but not with a class inherited from declarative_base
for row in data:
model_obj = DBEngine.models.User()
[setattr(model_obj, key, value) for key, value in row.items()]
# below line doesn't work as expected, instead of deleting the
# attribute it just sets the value of attribute to None
delattr(model_obj, 'localedit')
session.add(model_obj)
User model
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column('id', Integer, primary_key=True)
localedit = Column('localedit', String, default="0000-00-00 00:00:00")
I've also tried deleting the attribute using del but it's doing the same job as delattr, I guess both del and delattr calling the same code under the hood.
I'm totally stumped on this problem and couldn't come up with anything. Any help would be appreciated, Thanks.