Skip to content

Comments

Fix: Change defparameter to defvar to prevent configuration reset on reload#138

Merged
tamurashingo merged 2 commits intodevelopfrom
fix/database-config-reload-issue
Jan 28, 2026
Merged

Fix: Change defparameter to defvar to prevent configuration reset on reload#138
tamurashingo merged 2 commits intodevelopfrom
fix/database-config-reload-issue

Conversation

@tamurashingo
Copy link
Owner

Summary

Fixed an issue where configuration values defined with defparameter were reset to their initial values when <app> was reloaded during clails test comm
and execution.

Problem

When executing the clails test command, the following problem occurred:

  1. clails.boot loads <app> and initializes database configuration
  2. During test execution, <app> is reloaded because <app-test> depends on <app>
  3. Variables defined with defparameter are overwritten with initial values
  4. Database configuration is lost or becomes incomplete

The following variables were particularly affected:

  • clails/environment:*database-config*
  • clails/environment:*database-type*
  • Other application configuration variables

Changes

1. src/environment.lisp

Changed variables that application developers are expected to override from defparameter to defvar:

  • *project-name*
  • *project-dir*
  • *project-environment*
  • *database-config*
  • *database-type*
  • *migration-base-dir*
  • *task-base-dir*
  • *connection-pool*
  • *routing-tables*
  • *startup-hooks*
  • *shutdown-hooks*
  • *default-lock-mode*
  • *sqlite3-busy-timeout*
  • *sqlite3-lock-retry-count*
  • *sqlite3-transaction-mode*
  • *sqlite3-lock-module-loaded*
  • *table-information-initialized*
  • *query-initialization-callbacks*

2. src/middleware/transaction-middleware.lisp

  • Changed *enable-transaction-middleware* to defvar

3. src/middleware/core.lisp

  • Changed *clails-middleware-stack* to defvar

Rationale

defvar preserves existing values on re-evaluation, which is the standard Common Lisp behavior. This ensures:

  • Configuration values are preserved even when files are reloaded
  • Values set by application developers are not unintentionally reset
  • Correct configuration is maintained during test execution

Testing

  • Confirmed all existing tests pass
  • Verified database configuration is correctly preserved during clails test command execution

Related Issue

Fixes #137

- Change all defparameter to defvar to prevent variable reinitialization
- This fixes the issue where database configuration is reset when <app> is reloaded during test execution
- defvar preserves the value on re-evaluation, which is appropriate for application configuration variables
- Change *enable-transaction-middleware* to defvar (can be toggled by application)
- Change *clails-middleware-stack* to defvar (can be modified by add-middleware-* functions)
- Keep *lack-middleware-transaction* and *lack-middleware-clails-controller* as defparameter (not expected to change)
@tamurashingo tamurashingo merged commit f574bab into develop Jan 28, 2026
2 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.

Issue: Database Configuration Not Loaded Properly in clails test

1 participant