账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    升级marshmallow后有大量warning怎么快速修改?
    66
    0
    示例代码:# schemas.pyfrom marshmallow import Schemafrom marshmallow import fieldsclass FooSchema(Schema): name = fields.String( required=True, title='foo', description='foo name') relationship = fields.String( title='bar', description='foobar')测试代码:from schemas import FooSchemadef test_warn(): INPUT = { 'name': 'something', 'relationship': 'others' } schema = FooSchema() data = schema.load(INPUT) assert data == INPUT示例代码文件结构:.├── requirements.txt # marshmallow==3.3.0├── schemas.py└── test_warning.py升级 marshmallow:$ pip install -U marshmallow...Successfully installed marshmallow-3.14.1使用 pytest 测试(出现 marshmallow warning):pytest test_warning.py================================================================ test session starts =================================================================platform darwin -- Python 3.8.3, pytest-6.2.5, py-1.11.0, pluggy-1.0.0rootdir: /private/tmp/_collected 1 item test_warning.py . [100%]================================================================== warnings summary ==================================================================.venv/lib/python3.8/site-packages/marshmallow/fields.py:218 /private/tmp/_/.venv/lib/python3.8/site-packages/marshmallow/fields.py:218: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'title': 'foo', 'description': 'foo name'} warnings.warn(.venv/lib/python3.8/site-packages/marshmallow/fields.py:218 /private/tmp/_/.venv/lib/python3.8/site-packages/marshmallow/fields.py:218: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'title': 'bar', 'description': 'foobar'} warnings.warn(-- Docs: https://docs.pytest.org/en/stable/warnings.html=========================================================== 1 passed, 2 warnings in 0.03s ============================================================演示:修改为没有warning的代码:class FooSchema(Schema): name = fields.String( required=True, metadata={'title': 'foo', 'description': 'foo name'}) relationship = fields.String( metadata={'title': 'bar', 'description': 'foobar'})问题:如果有很多个 fields.XXXFieldYYY(...) 一个一个手动修改起来太难了,有没有什么快捷的方案一次性改好?
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 大漠书生 普通会员 1楼

      在升级marshmallow后,如果有大量warning,可能是由于以下原因:

      1. 模块依赖错误:检查marshmallow的依赖库和依赖项,确保它们与你的项目版本相符。例如,如果你的项目依赖了第三方库,而该库的版本与marshmallow版本不同,那么你可能会收到警告。在这种情况下,你可以尝试更新第三方库的版本或移除它,然后重新导入marshmallow依赖库。

      2. 依赖库未安装:在升级marshmallow后,确保你的项目依赖的依赖库已经安装并添加到你的项目中。如果没有安装,你可能会收到警告。可以通过运行pip install marshmallow命令来安装marshmallow依赖库。

      3. 版本冲突:如果你的项目使用了旧的marshmallow版本,并且你升级到了新的版本,那么可能会出现冲突。在这种情况下,你需要找到与旧版本冲突的模块或依赖项,然后进行修复或删除它们。例如,如果你的项目中使用了marshmallow中的marshmallow.Schema模块,而你的新版本的marshmallow版本中引入了marshmallow.fields.Field,那么你需要删除或重写与Field相关的模块。

      4. 非预期的行为:升级marshmallow后,可能会发生一些非预期的行为,如更改或移除marshmallow中原来不存在的模块或依赖项。在这种情况下,你可能需要查看详细的警告信息,以了解哪些行为是预期的,哪些行为是需要修改或删除的。

      5. 非法依赖:如果你的项目依赖了一个不安全的、不受信任的或非法的模块或依赖项,那么你可能会收到警告。在这种情况下,你需要检查这些依赖项,确保它们符合你的项目需求,并且不包含任何可能的安全漏洞或未受信任的组件。

      要快速修改警告,建议你按照以下步骤操作:

      1. 仔细阅读警告信息:仔细阅读每个警告信息,理解其含义和可能的原因。通常,警告信息会包含详细的错误描述、相关的代码行和版本信息等。

      2. 了解警告中的模块或依赖项:确认每个警告信息所涉及的模块或依赖项的名称、版本和功能。这些信息可以帮助你了解警告的来源和可能的原因。

      3. 查看代码或文档:查看使用这些模块或依赖项的代码或文档,查找任何潜在的安全漏洞或错误。如果可能,尝试修复或替换这些错误,或者添加新的安全检查和错误处理代码。

      4. 更新依赖库或模块:根据你的分析和修复,更新依赖库或模块,确保它们与你的项目版本保持一致。可以使用pip install命令来更新依赖库或模块。

      5. 测试和修复:重新运行你的项目,确保警告问题已经得到解决。如果问题仍然存在,可能需要进行更深入的测试和修复。

      6. 保持更新:在以后的开发过程中,建议你始终使用最新的marshmallow版本,并定期更新依赖库和模块,以避免出现新的警告和问题。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部