Encoded query with an invalid dot-walk returns ALL records (and how to protect bulk updates)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
17m ago
Hi Guys!
This happens because GlideRecord / GlideAggregate silently drop an invalid condition and run the rest of the query. The log shows Invalid query detected … Unknown field, but the script keeps going. For a count you just get a wrong number; for updateMultiple() or deleteMultiple() it can hit the whole table.
Step 1: Check what the reference field actually points to
A common case: cmdb_sam_sw_install.installed_on references cmdb_ci, not cmdb_ci_server. Fields that exist only on hardware classes are not reachable.
Find :
Replace with a field that exists on the referenced table:
Step 2: Add a guard before any bulk write
Step 3 (instance-wide, optional)
Set the system property glide.invalid_query.returns_no_rows = true so an invalid query returns 0 rows instead of all rows. Check with your platform owner first — existing scripts that rely on the old behavior will start returning nothing.
Bonus: != also drops empty values
Result: our check script reported 2.5M “retired” installs — that was the full table count. The correct number with a valid field was about 0.9M.
If this helped, please mark it as Helpful ! 🙂
無効な dot-walk を含むエンコードクエリが全件を返す(一括更新の守り方)
GlideRecord / GlideAggregate は 無効な条件を黙って無視し、残りの条件だけで実行します。ログには Invalid query detected … Unknown field が出ますが、スクリプトは止まりません。件数なら数字が間違うだけですが、updateMultiple() や deleteMultiple() では テーブル全体 が対象になり得ます。
Step 1: 参照フィールドの参照先を確認する
よくある例: cmdb_sam_sw_install.installed_on の参照先は cmdb_ci_server ではなく cmdb_ci です。ハードウェアクラスにしかないフィールドには届きません。
参照先テーブルに存在するフィールドに置換:
Step 2: 一括更新の前にガードを入れる
Step 3(インスタンス全体・任意)
システムプロパティ glide.invalid_query.returns_no_rows = true を設定すると、無効なクエリは全件ではなく 0 件を返します。既存スクリプトの動作が変わるため、プラットフォーム管理者に事前確認してください。
補足: != は空の値も除外する
結果: 確認スクリプトが Retired インストールを 250 万件と報告しましたが、実はテーブル全件数でした。正しいフィールドでは約 90 万件です。
参考になれば Helpful をお願いします