当我发布新的设备元素时,我无法添加相关报告
curl -X POST -H "Content-Type: application/json" -d '{
"reports": [1],
"short_description": "test1",
"code": "TEST"
}' "http://localhost:4000/devices"
我收到以下错误(服务器抛出500错误)。有任何想法吗?
数据库是sqlite,但我不认为它是相关的
由于
AttributeError:' int'对象没有属性' _sa_instance_state'
SQL Alchemy conf
engine = create_engine(config.DATABASE_URI, echo=True)
session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
ReportDevice = Table(
'report_devices',
Base.metadata,
Column('report_id', Integer, ForeignKey('reports._id')),
Column('device_id', Integer, ForeignKey('devices._id'))
)
class Report(CommonColumns):
__tablename__ = 'reports'
_id = Column(Integer, primary_key=True)
short_description = Column(String)
code = Column(String)
description = Column(String)
status = Column(String)
stored_procedure_id = Column(Integer, ForeignKey('stored_procedures._id'))
stored_procedure = relationship('StoredProcedure')
template_file = Column(String)
_fields = Column(String)
def __init__(self, _id, short_description, code, description,
status, template_file, fields, stored_procedure):
self._id = _id
self.short_description = short_description
self.code = code
self.description = description
self.status = status
self.stored_procedure = stored_procedure
self.template_file = template_file
self.fields = fields
@hybrid_property
def fields(self):
return self._fields.split(';')
@fields.setter
def set_fields(self, fields):
self._fields = ';'.join(fields)
def render(self):
env = Environment(loader=FileSystemLoader(config.TEMPLATES_DIR))
template = env.get_template(self.template_file)
data = self.store_procedure.execute(self.fields)
return template.render({'rows': data})
......
class Device(CommonColumns):
__tablename__ = 'devices'
_id = Column(Integer, primary_key=True)
short_description = Column(String)
code = Column(String)
description = Column(String)
location = Column(String)
status = Column(String)
reports = relationship('Report', secondary=ReportDevice, backref='Device')
rotation_interval = Column(Integer)
advertisement = Column(String)
夏娃
registerSchema('device')(Device)
registerSchema('report')(Report)
settings = {
'DEBUG': True,
'IF_MATCH': False,
'ENFORCE_IF_MATCH': False,
'SQLALCHEMY_DATABASE_URI': config.DATABASE_URI,
'DOMAIN': {
'devices': Device._eve_schema['device'],
'reports': Report._eve_schema['report']
}
}
settings['DOMAIN']['devices'].update({
'resource_methods': ['GET', 'POST', 'DELETE'],
'item_methods': ['GET', 'PATCH', 'DELETE']
})
app = Eve(validator=ValidatorSQL, data=SQL, settings=settings)