fix: an OCCT failure while reading a geometry type or closedness makes the property absent, as in 2.2.6

2.2.6 wrote `except Exception: return MISSING` around the OCP calls (ql._geometry_property); OCP's Standard_Failure is an
Exception there. The C++ port caught std::exception, which OCCT's exceptions do not derive from, so an OCCT failure in
shape_geom_type (reactive/geo_selection.cpp) and in geom.closed (ql/property.cpp: is_wire_closed / shell_is_closed,
which are not under occt_guard) escaped instead of yielding no value. Both now catch Standard_Failure explicitly.

DEVIATIONS.md records (with a test) the other difference found in the same review of a real agent session: a
scad.var expression used as a ql predicate value is evaluated here and matched nothing in 2.2.6.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NiJingzhe
2026-10-30 08:53:53 +08:00
parent fee292c3cd
commit f448af37f4
4 changed files with 47 additions and 4 deletions
+10
View File
@@ -143,3 +143,13 @@ test is a decision on record, not a gap.
| `test_inspect_brep_queries.py::test_render_worker_retries_crash_and_requires_clean_exit` | tests the crash-isolated VTK render worker subprocess and its retry policy; the soft renderer runs in-process |
| `test_render_screenshot_multiview.py` (3 tests: `..._grid_engine`, `..._multiview_engine_with_annotations`) | tests the routing between the VTK single-view engine and the grid engine; there is one engine |
| `test_sketch_api.py::...default_solver_backend_is_py_slvs...` (in `test/native_known_failures.json`) | the default sketch solver backend is `scad-native`; py-slvs (GPL) is not linked. A user-visible difference: the backend name in a sketch snapshot. See `sketch-solver.md` |
## A symbolic value in a ql predicate (native is more permissive than 2.2.6)
`ql.prop("geom.length", ">=", 2 * math.pi * plate_radius * 0.999)` where `plate_radius` is a `scad.var(...)`: the value
is an `Expr`. 2.2.6.post2 compares the measured number with the unevaluated expression, matches nothing and fails with
"expected exactly 2 edge(s), got 0" while its own inventory lists the arcs of the right length (an agent spent ten
minutes on this in a scan-to-CAD run: the fix was `float(plate_radius)`). This engine evaluates the expression, so the
query matches. The 2.2.6 behaviour is a defect rather than a contract, and no old test depends on it; it is recorded so
that a model written against this engine is known not to run unchanged on 2.2.6 (`float(...)` makes it portable).
Pinned by `tests/python/test_ql_symbolic_predicate.py`.
+6 -2
View File
@@ -4,6 +4,7 @@
#include <BRepAdaptor_Surface.hxx>
#include <GeomAbs_CurveType.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <Standard_Failure.hxx>
#include <TopoDS.hxx>
#include <algorithm>
@@ -441,8 +442,11 @@ std::optional<Value> PropertyPath::lookup(const Shape& shape, const EvalContext&
if (kind == Kind::Shell)
return Value(kernel::shell_is_closed(shape.wrapped()));
} catch (const std::exception&) {
// Kept broad: kernel::is_wire_closed/shell_is_closed are not under occt_guard, so this is not
// known to be narrowable. A closedness the kernel cannot tell is a missing property.
return std::nullopt; // a closedness the kernel cannot tell is a missing property
} catch (const Standard_Failure&) {
// kernel::is_wire_closed / shell_is_closed are not under occt_guard, and OCCT's exceptions do not derive
// from std::exception. 2.2.6 wrote `except Exception: return MISSING` around the same OCP calls
// (ql._geometry_property), where OCP's Standard_Failure is an Exception: the property is missing.
return std::nullopt;
}
return std::nullopt;
+5 -2
View File
@@ -4,6 +4,7 @@
#include <BRepAdaptor_Surface.hxx>
#include <GeomAbs_CurveType.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <Standard_Failure.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
@@ -130,8 +131,10 @@ std::optional<std::string> shape_geom_type(const Shape& shape) {
if (shape.kind() == Kind::Face)
return surface_type(BRepAdaptor_Surface(TopoDS::Face(shape.wrapped())).GetType());
} catch (const std::exception&) {
// Kept broad on purpose: OCCT's Standard_Failure does not derive from std::exception, so this catch is
// not known to be narrowable (see the report). A shape without a readable geometry type has none.
return std::nullopt; // a shape without a readable geometry type has none
} catch (const Standard_Failure&) {
// OCCT's exceptions do not derive from std::exception. 2.2.6 wrote `except Exception` around the same OCP
// calls, and OCP's Standard_Failure is an Exception there: the type is absent, not an error.
return std::nullopt;
}
return std::nullopt;
@@ -0,0 +1,26 @@
"""A symbolic value (an Expr from scad.var arithmetic) in a ql predicate is evaluated, not compared as an object.
2.2.6.post2 matches nothing here (see docs/DEVIATIONS.md): this is a recorded deviation, in the permissive direction.
"""
from __future__ import annotations
import math
import simplecadapi as scad
from simplecadapi import ql
def test_a_var_expression_in_a_predicate_matches_like_the_float() -> None:
radius = scad.var(name="plate_radius", default=50.0, unit="mm")
solid = scad.make_cylinder_rsolid(float(radius), 10)
def rims(length) -> int:
selector = ql.edges().where(
ql.and_(ql.prop("geom.length", ">=", length * 0.999), ql.prop("geom.length", "<=", length * 1.001))
)
return len(ql.select(selector.resolve(solid)).all())
assert rims(2 * math.pi * 50.0) == 2
assert rims(2 * math.pi * radius) == 2
assert rims(2 * math.pi * float(radius)) == 2