I am using Flask and SqlAlchemy to build an API, but having a problem with fields.Url()
, which I cannot figure out. I am getting the following error:
BuildError: ('storagenode_ep', MultiDict([('_sa_instance_state', <sqlalchemy.orm.state.InstanceState object at 0x4a76ad0>), ('id', 7), ('hostname', u'testNode1')]), None)
It works fine if I just return the id instead of trying to use field.Url()
.
The following simplified class demonstrates the issue:
storagenode_fields = {
'hostname': fields.String,
'uri': fields.Url('storagenode_ep')
# 'id': fields.String
}
class StorageNodeAPI(Resource):
@marshal_with(storagenode_fields)
def get(self, storagenode_id):
return StorageNode.query.filter_by(id=storagenode_id).first()
api.add_resource(StorageNodeAPI, '/api/storagenodes/<string:storagenode_id>', endpoint='storagenode_ep')
I have read this to better understand how endpoints, but I am still stuck.
The StorageNode class
is defined as follows:
class StorageNode(Base):
__tablename__ = 'storagenode'
id = Column(Integer, primary_key=True)
hostname = Column(String(150), unique=True)