TypeError: '_updated' is an invalid keyword argument for Network
Hi,
When I try to post a JSON payload via my endpoint /network, I get the following error.
TypeError: '_updated' is an invalid keyword argument for Network
I would assume that inserting into the DB via POST should be fairly trivial without requiring anything else.
Am I missing any additional configuration at all?
Eve v0.7.10 Eve-SQLAlchemy v0.7.1 Flask:0.12 Werkzeug: 0.11.15
Thanks!
Full error message is here: https://gist.github.com/virtualvinodh/ced063f382a2cd1c397cee28f736b9ea
Base = declarative_base()
metadata = Base.metadata
class Network(Base):
__tablename__ = 'network'
__table_args__ = {'comment': 'Networks group.'}
network_id = Column(NUMBER(22, 0, False), primary_key=True, comment='Network identity')
name = Column(VARCHAR(50), comment='Network name')
created_date = Column(DateTime, server_default=text("SYSDATE"), comment='Internal / log field. Timestamp of creation')
created_by = Column(VARCHAR(40), nullable=False, server_default=text("'admin' "), comment='Internal / log field. Username who created the object')
SETTINGS = {
'DEBUG': True,
'RESOURCE_METHODS': ['GET', 'POST'],
'SQLALCHEMY_DATABASE_URI': oracle_connection_string,
'SQLALCHEMY_ECHO': True,
'SQLALCHEMY_RECORD_QUERIES': True,
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
'DOMAIN': DomainConfig({
'network': ResourceConfig(Network)
}).render()
}
app = Eve(auth=None, settings=SETTINGS, validator=ValidatorSQL, data=SQL)
db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base
app.run(debug=True)
I fixed this by adding a bunch of conditionals at sqlalchemy.ext.declarative.base
I'm sure this isn't the right way to do this.
Line: 386
cls_ = type(self)
for k in kwargs:
if k == "_updated" or k == "_created" or k=="_etag":
pass
elif not hasattr(cls_, k):
raise TypeError(
"%r is an invalid keyword argument for %s" % (k, cls_.__name__)
)
setattr(self, k, kwargs[k])
You haven't created _updated field in your Network class which is necessary for POST operations as it is part of Eve core functionality.
From Eve-sqlalchemy tutorial (https://eve-sqlalchemy.readthedocs.io/en/latest/tutorial.html#eve-settings):
We have used CommonColumns abstract class to provide attributes used by Eve, such as _created and _updated. These are not needed if you are only reading from the database. However, if your API is also writing to the database, then you need to include them.