Skip to content

Conversation

@pyramation
Copy link
Contributor

Summary

Fixes TypeError: Cannot read properties of undefined (reading 'anonymous') when running pgpm admin-users bootstrap.

The root cause was that getConnEnvOptions() could return undefined for roles and connections if a config file or environment explicitly set these to undefined, bypassing the deepmerge defaults. This PR:

  1. Fixes the merge logic in getConnEnvOptions to explicitly spread defaults for roles and connections, ensuring they're always resolved
  2. Adds defensive validation in SQL generators to throw clear errors if roles/connections are undefined
  3. Adds tests to prevent regression

Review & Testing Checklist for Human

  • Verify the getConnEnvOptions change doesn't break existing config overrides - the tests show partial overrides still work, but worth confirming with your actual config files
  • Test pgpm admin-users bootstrap --yes works with the fix
  • Test pgpm admin-users add and pgpm admin-users remove still work (they use the same SQL generators)
  • Consider if there are other places in the codebase that might have similar issues with optional nested properties not being resolved from defaults

Recommended test plan:

# Run the command that was failing
pgpm admin-users bootstrap --yes

# Verify other admin-users commands work
pgpm admin-users add --username testuser --password testpass --yes
pgpm admin-users remove --username testuser --yes

Notes

  • The exact root cause of why deepmerge wasn't preserving defaults wasn't fully determined (could be a config file setting db.roles: undefined, version mismatch in global install, etc.). This fix ensures defaults are always applied regardless.
  • Added jest.config.js to pgpm/env package to enable running the new tests

Link to Devin run: https://app.devin.ai/sessions/3a8e8acb237e4b08bc1878defcf041f0
Requested by: Dan Lynch (@pyramation)

…n getConnEnvOptions

- Fix root cause: getConnEnvOptions now explicitly merges defaults for roles and connections
  to prevent undefined values even if config/env explicitly sets them to undefined
- Add defensive validation in SQL generators (generateCreateBaseRolesSQL, generateCreateUserSQL,
  generateCreateTestUsersSQL, generateRemoveUserSQL) to throw clear errors if roles is undefined
- Add comprehensive tests for roles SQL generators input validation
- Add tests for getConnEnvOptions to verify defaults are always resolved

Fixes TypeError: Cannot read properties of undefined (reading 'anonymous') in admin-users bootstrap

Co-Authored-By: Dan Lynch <pyramation@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation closed this Dec 22, 2025
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