Skip to content

[Bug]: augmentations.rs: dict_get panics on missing key instead of raising PyErr #1058

Description

@khushi-070906

🐛 Describe the bug

/// Extract a required key from a params dict.
///
/// Panics on missing key to match the previous unwrap() behavior at each call site.
fn dict_get<'py, T>(d: &Bound<'py, PyDict>, key: &str) -> PyResult
where
T: for<'a> FromPyObject<'a, 'py, Error = PyErr>,
{
d.get_item(key)?.unwrap().extract::()
}

🔄 Steps to Reproduce

Despite the PyResult return signature, a missing key currently panics via .unwrap() rather than returning Err. This is used across the params= path of every transform's __call__ (RandomHorizontalFlip, RandomVerticalFlip, RandomCrop, RandomRotation, etc.) — a malformed or incomplete params dict supplied by user code crashes the interpreter thread instead of raising a catchable Python exception.

💻 Minimal Code Example

✅ Expected behavior

Location: apply_saturation_neon and apply_saturation_scalar (plus the fused-LUT helpers they support: build_linear_lut, apply_lut, byte_mean) live in kornia_imgproc (or kornia_image, whichever crate owns comparable pixel kernels like rgb_to_gray_u8), not in the augmentations.rs PyO3 bindings file. augmentations.rs calls into that crate the same way blur.rs calls filter::gaussian_blur_u8, color.rs calls color::rgb_from_gray, etc. — a thin marshalling wrapper only.

❌ Actual behavior

return Err(PyValueError::new_err(...)) on a missing key, naming the missing key and the transform.

🔧 Environment

- kornia-rs version:
- Rust version (`rustc -V`):
- Cargo version (`cargo -V`):
- OS (e.g., Linux, macOS, Windows):
- Target architecture (if cross-compiling):
- Python version (if using Python bindings):

📝 Additional context

No response

🤝 Contribution Intent

  • I plan to submit a PR to fix this bug
  • I'm reporting this bug but not planning to fix it

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededtriagewait for a maintainer to approve and assign this ticket

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions