关闭 sqlalchemy 中的警告
我使用 sqlalchemy 进行反射,数据库中的几个部分索引使其转储如下警告:
SAWarning: Predicate ofpartial index i_some_index在反射期间被忽略
到我的日志中并保持混乱。它不会妨碍我的应用行为。我想在开发过程中保留这些警告,但不要在生产级别保留这些警告。有谁知道如何关闭此功能?
I'm using sqlalchemy with reflection, a couple of partial indices in my DB make it dump warnings like this:
SAWarning: Predicate of partial index i_some_index ignored during reflection
into my logs and keep cluttering. It does not hinder my application behavior. I would like to keep these warnings while developing, but not at production level. Does anyone know how to turn this off?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 的 警告模块 提供了一个方便的 上下文管理器 为您捕获警告。
以下是如何过滤掉 SQLAlchemy 警告。
至于开发与生产,您可以将此警告包含在应用程序的入口点或在生产环境中调用应用程序的外部脚本中。
通常,我通过使用一个环境变量来解决这个问题,该环境变量执行的代码路径与开发时略有不同,例如,包装不同的中间件等。
Python's warning module provides a handy context manager that catches warnings for you.
Here's how to filter out the SQLAlchemy warning.
As for development vs production, you can just have this warning wrap around your application's entry point or an external script that invokes your application in your production environment.
Usually, I solve this by having an environment variable that executes a slightly different code path than when developing, for example, wrapping around different middleware etc.
该警告意味着您进行了表或元数据反射,并且它正在读取具有某些复杂条件的 postgresql 索引,而 SQLAlchemy 反射代码不知道如何处理这些条件。这是一个无害的警告,因为无论是否反映索引都不会影响应用程序的操作,除非您想为另一个数据库上的这些表/索引重新发出 CREATE 语句。
the warning means you did a table or metadata reflection, and it's reading in postgresql indexes that have some complex condition which the SQLAlchemy reflection code doesn't know what to do with. This is a harmless warning, as whether or not indexes are reflected doesn't affect the operation of the application, unless you wanted to re-emit CREATE statements for those tables/indexes on another database.