Skip to content
This repository was archived by the owner on Nov 26, 2026. It is now read-only.

fix(deserialize): call pyutil_mongo.db_find_one in deserialize_board_summary - #25

Open
PttCodingMan wants to merge 1 commit into
mainfrom
fix/board-summary-find-one
Open

PttCodingMan wants to merge 1 commit into
mainfrom
fix/board-summary-find-one

Conversation

@PttCodingMan

Copy link
Copy Markdown
Member

這個 PR 的目的 / Purpose of this PR

deserialize_board_summary() 在沒有傳入 read_map 時,會呼叫 pyutil_mongo.find_one(...),但 pyutil_mongo 並沒有這個函式(正確名稱是 db_find_one),因此這條路徑一定會丟出 AttributeError。本 PR 改成呼叫 pyutil_mongo.db_find_one。db_find_one 找不到資料時回傳 {},所以後面的 .get('update_milli_ts', 0) 可以正常運作。

When deserialize_board_summary() is called without read_map, it calls pyutil_mongo.find_one(...), which does not exist in pyutil_mongo (the function is db_find_one). That code path always raised AttributeError. This PR calls pyutil_mongo.db_find_one instead; it returns {} when no document matches, so the following .get('update_milli_ts', 0) works.

驗證 / Verification

環境:Python 3.10 venv,依 setup.py 安裝 Flask-Security-Too 3.4.4、flask-mongoengine 1.0.0 等(另外 pin mongoengine==0.20.0、pymongo<4),測試使用 mongomock,不需要真的 MongoDB。nose 1.3.7 在 Python 3.10 無法執行,所以改用 pytest<8 並以暫時的 conftest.py(不 commit)呼叫 tests.setup()。

Environment: Python 3.10 venv with the setup.py dependencies (plus mongoengine==0.20.0, pymongo<4); tests use mongomock, no real MongoDB needed. nose 1.3.7 does not run on Python 3.10, so I used pytest<8 with a temporary, uncommitted conftest.py that calls tests.setup().

  • 新增的回歸測試 test_deserialize_board_summary_without_read_map,在修正前失敗:AttributeError: module 'pyutil_mongo' has no attribute 'find_one'

  • 修正後 python -m pytest -q tests:50 passed

  • The new regression test test_deserialize_board_summary_without_read_map fails before the fix with AttributeError: module 'pyutil_mongo' has no attribute 'find_one'.

  • After the fix, python -m pytest -q tests: 50 passed.

相關的 issue / Related Issues

無 / None

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant