Skip to content

Clean up and refactor demographics collection#40

Merged
a-hurst merged 7 commits into
testingfrom
demographics_cleanup
May 7, 2026
Merged

Clean up and refactor demographics collection#40
a-hurst merged 7 commits into
testingfrom
demographics_cleanup

Conversation

@a-hurst
Copy link
Copy Markdown
Owner

@a-hurst a-hurst commented May 7, 2026

PR Description

This PR streamlines basic demographics collection in KLibs ahead of larger changes to the participant initialization and demographics code (code versioning rewrite, multisession). This is largely based on the earlier commits in #31, with some additional cleanup and tests.

The biggest functional change is that behaviour is now less surprising when the participant columns in the database and the defined user queries are out of sync (column added without a query or query added without a column). Demographics collection will now check that every required column in the participants table (i.e. every non-internal column that's NOT NULL and/or lacks a default value) has a corresponding query and will immediately raise an informative error immediately if any are missing (would previously only fail at the end of demographics collection). Conversely, if a query has been defined that doesn't have a corresponding column in the participants table, it will be skipped over and a warning will be printed to the console.

Another change is that the query for the participant's unique identifier is now guaranteed to always be asked first, which is necessary for future multisession support.

This PR also ensures that the participant has been initialized in the database prior to the start of the first block (otherwise trial data can't be logged), and additionally ensures that collect_demographics isn't called more than once (e.g. called manually in the code but P.manual_demographics_collection wasn't enabled so it gets called again).

Usage of the deprecated EntryTemplate class has been removed for simplicity, leaving trial logging as the only part of KLibs where it's still used.

Merge Checklist

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in CHANGELOG.rst

@a-hurst a-hurst merged commit 89bd901 into testing May 7, 2026
18 checks passed
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.

1 participant