plandex-ai/plandex · error
error getting orgs from invites: %v
Error message
error getting orgs from invites: %v
What it means
The final wrapped failure in GetAccessibleOrgsForUser: the SELECT fetching org rows referenced by the user's pending invites. Fires when Conn.Select on orgsFromInvites fails (connection, missing table, nonexistent column in orgFields, or scan mismatch). Only runs when invite-derived orgIds is non-empty.
Source
Thrown at app/server/db/org_helpers.go:62
// access via invitation
invites, err := GetPendingInvitesForEmail(user.Email)
if err != nil {
return nil, fmt.Errorf("error getting invites for user: %v", err)
}
orgIds = []string{}
for _, invite := range invites {
orgIds = append(orgIds, invite.OrgId)
orgRoleIdByOrgId[invite.OrgId] = invite.OrgRoleId
}
if len(orgIds) > 0 {
var orgsFromInvites []*Org
query := fmt.Sprintf("SELECT %s FROM orgs WHERE id = ANY($1)", orgFields)
err = Conn.Select(&orgsFromInvites, query, pq.Array(orgIds))
if err != nil {
return nil, fmt.Errorf("error getting orgs from invites: %v", err)
}
orgs = append(orgs, orgsFromInvites...)
}
return orgs, nil
}
func GetOrg(orgId string) (*Org, error) {
var org Org
query := fmt.Sprintf("SELECT %s FROM orgs WHERE id = $1", orgFields)
err := Conn.Get(&org, query, orgId)
if err != nil {
if err == sql.ErrNoRows {
return nil, fmt.Errorf("org not found")
}
return nil, fmt.Errorf("error getting org: %v", err)
}View on GitHub (pinned to e2d772072e)
Solutions
- Read the wrapped error: 'column does not exist' → fix orgFields; scan error → align Org struct tags
- Keep orgFields synchronized with the orgs schema
- Run pending migrations
- Consider INNER JOIN orgs to invites instead of two queries to avoid orphan-invite gaps
Example fix
// before
query := fmt.Sprintf("SELECT %s FROM orgs WHERE id = ANY($1)", orgFields)
err = Conn.Select(&orgsFromInvites, query, pq.Array(orgIds))
// after
query := fmt.Sprintf("SELECT DISTINCT o.%s FROM orgs o JOIN invites i ON i.org_id = o.id WHERE i.email = $1 AND i.status = 'pending'", strings.ReplaceAll(orgFields, ", ", ", o.")) Defensive patterns
Strategy: try-catch
Validate before calling
// startup: assert all orgFields columns exist on orgs
const orgFields = "id, name, created_at, updated_at"
var n int
for _, col := range strings.Split(orgFields, ", ") {
Conn.Get(&n, "SELECT count(*) FROM information_schema.columns WHERE table_name='orgs' AND column_name=$1", col)
// fail fast if n == 0
} Type guard
func isUndefinedColumn(err error) bool {
var pgErr *pgconn.PgError
return errors.As(err, &pgErr) && pgErr.Code == "42703"
} Try / catch
orgs, err := db.GetAccessibleOrgsForUser(user)
if err != nil {
if isUndefinedColumn(errors.Unwrap(err)) { log.Printf("orgs schema drift: %v", err) }
return err
} Prevention
- Keep orgFields synchronized with the orgs schema after migrations
- Prefer a single JOIN over the two-step orgIds query to reduce failure surface
- Run migrations in every environment
- Wrap with %w to preserve the driver error
- Add a smoke test that lists orgs for a seeded user with invites
When it happens
Trigger: orgs table missing or unreachable; orgFields names a column absent from orgs; Org struct cannot scan the returned columns; orgIds array passed via pq.Array is fine but the query errors for another driver reason.
Common situations: Schema drift between orgFields and the orgs table after a migration; an invite points at a deleted org (row simply absent — no error); DB restart during org listing.
Related errors
- error deleting custom models: %v
- error deleting custom providers: %v
- error fetching model packs: %v
- error deleting model pack: %v
- error getting orgs for user: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/db6ff4c76de69e91.
Report an issue: GitHub.