Skip to content

fix(behavior): guard log_activity against unset logger#9

Open
SAY-5 wants to merge 1 commit into
ef-lab:mainfrom
SAY-5:fix/log-activity-no-logger
Open

fix(behavior): guard log_activity against unset logger#9
SAY-5 wants to merge 1 commit into
ef-lab:mainfrom
SAY-5:fix/log-activity-no-logger

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 12, 2026

Description

Fixes #7.

RPPorts arms GPIO Lick/Proximity callbacks in __init__, but Behavior.logger is only set later in Behavior.setup(). A buffered edge between those two points fires the callback while self.logger is still None, and log_activity crashes on self.logger.logger_timer.elapsed_time() / self.logger.trial_key. RPi.GPIO swallows the exception on its C thread, the session continues, and the event is silently dropped.

This guards the early-fire window: if self.logger is unset, log a warning and return the activity time without touching self.logger.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Added test_log_activity_before_logger_setup in tests/test_behavior.py. It sets behavior.logger = None and asserts log_activity returns the activity time instead of raising AttributeError.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: SAY-5 <say.apm35@gmail.com>
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.

[BUG] Lick/proximity GPIO callbacks fire before Behavior.logger is set → AttributeError

1 participant