Setting trackerFileExtension to the instrument name fails with a SQL syntax error, or is silently ignored
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
調査の方向性
update_instrument(src/db_service.rs 内)から始めます。tracker_file_extension の分岐では、値がインストゥルメント名と等しいとフィールドをスキップし、UPDATE を組み立てる前に is_empty() のチェックが実行されます。issue の手順 2 と 4 のとおり、trackerFileExtension にインストゥルメント名を設定した状態で configure を実行して再現します。完了条件は、その呼び出しで行が更新されること(提案された修正のとおり NULL が保存されること)、空の SET が生成されないこと、そして insert_new が同じ値を保存することです。
索引モデルが issue の本文から書いたものです。
説明
Summary
configure skips a trackerFileExtension that equals the instrument name (src/db_service.rs, update_instrument):
if let Some(ext) = &self.tracker_file_extension {
if ext != &self.name {
// extension defaults to instrument name
fields.push("tracker_file_extension=");
fields.push_bind_unseparated(ext);
}
}
This causes two problems:
- SQL syntax error. When the extension is the only field being updated, the
is_empty()check passes (the extension isSome), but no field is added to theSETlist. The query becomesUPDATE instrument SET WHERE name = ? RETURNING *, and the mutation returns
error returned from database: (code: 1) near "WHERE": syntax error. - The extension can't be reset to the default. Once an extension has been set to something else, setting it back to the instrument name is silently dropped. If another field is updated in the same call, the mutation succeeds and returns the old extension unchanged.
A related inconsistency: creating an instrument with trackerFileExtension equal to its name stores it explicitly. The check only applies to updates. So two instances that behave identically can report null and "b01-1" for the same instrument.
Steps to reproduce (v1.1.0, also in v1.0.1)
git checkout v1.1.0
cargo build
./target/debug/numtracker serve --db repro.db --port 8123
Run each mutation against http://localhost:8123/graphql, for example in graphiql:
1. Create an instrument without an extension. This works and returns trackerFileExtension: null.
mutation {
configure(instrument: "b01-1", config: {
directory: "/tmp/{instrument}/data/{year}/{visit}"
scan: "{subdirectory}/{instrument}-{scan_number}"
detector: "{subdirectory}/{instrument}-{detector}-{scan_number}"
}) { instrument trackerFileExtension }
}
2. Set the extension to the instrument name. ❌ This returns the SQL syntax error.
mutation {
configure(instrument: "b01-1", config: { trackerFileExtension: "b01-1" }) { instrument trackerFileExtension }
}
{"data":null,"errors":[{"message":"error returned from database: (code: 1) near \"WHERE\": syntax error","path":["configure"]}]}
3. Set the extension to something else. This works and returns trackerFileExtension: "other".
mutation {
configure(instrument: "b01-1", config: { trackerFileExtension: "other" }) { instrument trackerFileExtension }
}
4. Try to set it back to the instrument name, with another field. ❌ This succeeds, but the extension is still "other".
mutation {
configure(instrument: "b01-1", config: { trackerFileExtension: "b01-1", scanNumber: 5 }) { instrument trackerFileExtension }
}
{"data":{"configure":{"instrument":"b01-1","trackerFileExtension":"other"}}}
5. Create a different instrument with the extension equal to its name. This stores it explicitly (trackerFileExtension: "i22"), which isn't consistent with step 2.
mutation {
configure(instrument: "i22", config: {
directory: "/tmp/{instrument}/data/{year}/{visit}"
scan: "{subdirectory}/{instrument}-{scan_number}"
detector: "{subdirectory}/{instrument}-{detector}-{scan_number}"
trackerFileExtension: "i22"
}) { instrument trackerFileExtension }
}
Expected
- Setting the extension to the instrument name updates it. In the database, that means setting
tracker_file_extensiontoNULL(the default) or to the name; either works, sinceNumTracker::for_instrumentfalls back to the instrument name withext.unwrap_or(bl). - An update that ends up with no fields to set returns the current configuration, as
is_empty()already does, instead of running an invalidUPDATE.
Suggested fix
In update_instrument, write NULL when the extension equals the name instead of skipping it:
if let Some(ext) = &self.tracker_file_extension {
fields.push("tracker_file_extension=");
// extension defaults to instrument name, so store NULL rather than duplicating it
fields.push_bind_unseparated((ext != &self.name).then_some(ext));
}
This fixes all three problems: no empty SET, the extension can be reset, and the default is stored the same way every time. insert_new could normalise the same way for consistency.
How this was found
An integration test comparing the configurations query on prod and staging reported b01-1 as null on one and "b01-1" on the other. Trying to align them with the configure mutation hit the syntax error.
- 主要言語
- Rust
- スター
- 1
- フォーク
- 2
- 平均マージ
- 14日 15時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DiamondLightSource/numtracker のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
DiamondLightSource/numtracker#309 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
DiamondLightSource/numtracker#278 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
DiamondLightSource/numtracker#310 ·
-
難易度 2/5 1時間未満 初心者へのやさしさ 15/100
DiamondLightSource/numtracker#308 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 58/100
DiamondLightSource/numtracker#304 ·
DiamondLightSource/numtracker の issue をすべて見る
似ている issue
-
area:gc-repack-output bug factory:dogfood factory:triaged priority:p3 type:bug type:ux
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gitbutlerapp/grit#1161 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
feature
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
storytold/photocraft#7520 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信