Skip to content

Conversation

@GDYendell
Copy link
Contributor

@GDYendell GDYendell commented Jan 30, 2026

This fix handles a case for the odin meta writer where it returns None for a String datatype. The problem was that it was correctly using the validated value to set the readback, but the original value to set the setpoint.

This also fixes a potential issue that initially thought was the problem where String.length is None and used to truncate strings in the EPICS CA transport and improves some trace messages that made this issue much easier to figure out. Using repr(value) in log messages means strings appear as 'None' instead of None.

It was already doing the right thing in the other case here.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected attribute setpoint callback behavior during initialization to use proper attribute values.
  • Improvements

    • Enhanced debugging experience with clearer logging output across attribute management and EPICS transport layers.
  • Tests

    • Added test coverage for attribute update functionality including numeric type conversions, validation errors, and synchronous setpoint callback behavior.

@GDYendell GDYendell requested a review from shihab-dls January 30, 2026 11:19
@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.79%. Comparing base (3fe7b0c) to head (9b9cd3f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #315   +/-   ##
=======================================
  Coverage   90.79%   90.79%           
=======================================
  Files          70       70           
  Lines        2542     2543    +1     
=======================================
+ Hits         2308     2309    +1     
  Misses        234      234           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GDYendell GDYendell force-pushed the setpoint-set-validation branch 3 times, most recently from 9369eba to c8ee243 Compare February 2, 2026 13:08
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

Changes improve logging consistency by converting values to repr() format across attribute and transport modules, fix a parameter name typo in logging, and modify setpoint callback behavior in AttrRW to use the stored value instead of the provided value during first initialization. A new test verifies this callback behavior and value casting.

Changes

Cohort / File(s) Summary
Logging improvements with repr()
src/fastcs/attributes/attr_r.py, src/fastcs/transports/epics/ca/ioc.py
Convert value logging to use repr(value) for consistent representation in logs across attribute updates and PV operations. Fixes typo: target_valuevaluetarget_value in attr_r.py.
Setpoint callback behavior
src/fastcs/attributes/attr_rw.py
When setpoint is not yet initialized, the first synchronous setpoint callback now uses self._value instead of the provided value parameter.
Test addition
tests/test_attributes.py
New async test test_attr_update verifying AttrRW(Int()) behavior including value casting from strings, callback registration, and callback invocation logic across multiple update scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through logs so neat,
With repr() making values sweet!
Callbacks dance with self._value true,
And tests ensure they all work through! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Call sync setpoint callbacks with validated value' accurately summarizes the main change: ensuring sync setpoint callbacks receive validated values instead of raw input values.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch setpoint-set-validation

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/fastcs/attributes/attr_r.py (1)

76-98: ⚠️ Potential issue | 🟡 Minor

Log callback failure with the validated value.

Callbacks are invoked with self._value, so logging repr(value) on failure can mislead when casting occurs (e.g., "100"100). Prefer logging the validated value (and optionally keep the raw input in a separate field).

🔧 Suggested fix
-                logger.opt(exception=e).error(
-                    "On update callbacks failed", attribute=self, value=repr(value)
-                )
+                logger.opt(exception=e).error(
+                    "On update callbacks failed",
+                    attribute=self,
+                    value=repr(self._value),
+                )
🤖 Fix all issues with AI agents
In `@src/fastcs/transports/epics/ca/util.py`:
- Around line 148-150: The slice uses a falsy check that treats length==0 as
None; update the case handling for the pattern "case String() as string" to
compute max length with an explicit None check (use string.length if
string.length is not None else DEFAULT_STRING_WAVEFORM_LENGTH) and then slice
value[:max_len]; reference the String pattern and DEFAULT_STRING_WAVEFORM_LENGTH
so the semantics preserve a legitimate zero length.

@GDYendell GDYendell force-pushed the setpoint-set-validation branch from c8ee243 to 2320e58 Compare February 2, 2026 13:46
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/fastcs/attributes/attr_r.py (1)

205-207: ⚠️ Potential issue | 🟡 Minor

Typo in keyword argument: target_valuevalue should be target_value.

Line 206 has a duplicated "value" in the keyword argument name, which will cause the log event to have an incorrectly named parameter.

🐛 Proposed fix
         self.log_event(
-            "Value equals target value", target_valuevalue=target_value, attribute=self
+            "Value equals target value", target_value=target_value, attribute=self
         )

@GDYendell GDYendell force-pushed the setpoint-set-validation branch from 5c0ebf7 to a81baec Compare February 2, 2026 14:05
Improve trace logging of attribute set
@GDYendell GDYendell force-pushed the setpoint-set-validation branch from a81baec to 9b9cd3f Compare February 2, 2026 14:07
@GDYendell GDYendell removed the request for review from shihab-dls February 2, 2026 14:31
@GDYendell GDYendell merged commit a9db2b6 into main Feb 2, 2026
11 checks passed
@GDYendell GDYendell deleted the setpoint-set-validation branch February 2, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants