我遇到了同样的问题并搜索了两天,才发现错误之前的代码包含错误:
它收到以下错误,指的是 python 和 sqlalchemy 中的错误
offertemodule_1 | File "/opt/packages/database/models.py", line 79, in process_bind_param
offertemodule_1 | return "%.32x" % uuid.UUID(value).int
offertemodule_1 | File "/usr/local/lib/python3.7/uuid.py", line 157, in __init__
offertemodule_1 | hex = hex.replace('urn:', '').replace('uuid:', '')
offertemodule_1 | sqlalchemy.exc.StatementError: (builtins.AttributeError) 'builtin_function_or_method' object has no attribute 'replace'
offertemodule_1 | [SQL: SELECT product.id AS product_id, product.supplier_id AS product_supplier_id, product.supplier_product_url AS product_supplier_product_url, product.supplier_product_id AS product_supplier_product_id, product.title AS product_title, product.description AS product_description, product.brand AS product_brand, product.product_line AS product_product_line, product.buying_price_ex_vat AS product_buying_price_ex_vat, product.buying_vat AS product_buying_vat, product.vat_pct AS product_vat_pct, product.advise_price AS product_advise_price, product.estimated_days_leadtime AS product_estimated_days_leadtime, product.product_category AS product_product_category, product.nestedproducts AS product_nestedproducts, product.atttibutes_meta AS product_atttibutes_meta, product.statistics_meta AS product_statistics_meta, product.active AS product_active, product.created AS product_created, product.created_by AS product_created_by, product.modified AS product_modified, product.modified_by AS product_modified_by
offertemodule_1 | FROM product
offertemodule_1 | WHERE product.id = %(id_1)s]
offertemodule_1 | [parameters: [immutabledict({})]]
但事实证明,在此之前的一个进程将错误的对象发送到我的数据库函数
@ns_products.route('/<string:product_id>')
@api.response(404, 'product not found.')
class Details(Resource):
@api.marshal_with(product)
@api.doc(security='jwt')
@jwt_required
def get(self, product_id):
'''Returns a single product instance'''
return Product.get(id)`
应该是(注意'product_id')
@ns_products.route('/<string:product_id>')
@api.response(404, 'product not found.')
class Details(Resource):
@api.marshal_with(product)
@api.doc(security='jwt')
@jwt_required
def get(self, product_id):
'''Returns a single product instance'''
return Product.get(product_id)
因此,存储在 product_id 中的 uuid 字符串实际上是本机 python 对象“id”。因此,它尝试将字符串处理为 uuid,但失败了。