Skip to content

Panic on user creation #2277

Closed
Closed
@Plorenzo

Description

I'm getting a panic when trying to create a new user from an api call. It happens in v0.14.3 and v0.14.4

2023/04/12 20:36:12 [PANIC RECOVER] runtime error: invalid memory address or nil pointer dereference goroutine 14 [running]:
github.com/labstack/echo/v5/middleware.RecoverConfig.ToMiddleware.func1.1.1()
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/labstack/echo/v5@v5.0.0-20220201181537-ed2888cfa198/middleware/recover.go:72 +0xd8
panic({0x10283e780, 0x10322f5b0})
	/opt/homebrew/Cellar/go/1.20.2/libexec/src/runtime/panic.go:884 +0x1f4
github.com/pocketbase/pocketbase/forms.(*RecordUpsert).Submit.func1.2(0x140001c1b20?, {0x1029e4918, 0x140001c1b20})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/forms/record_upsert.go:764 +0x30
github.com/pocketbase/pocketbase/daos.(*Dao).update(0x1400062a660, {0x1029e4918, 0x140001c1b20})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:245 +0xb8
github.com/pocketbase/pocketbase/daos.(*Dao).Save.func2(0x0?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:229 +0x24
github.com/pocketbase/pocketbase/daos.(*Dao).lockRetry.func1(0x140008e87f8?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:337 +0x188
github.com/pocketbase/pocketbase/daos.baseLockRetry(0x140008e8838, 0x8)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base_retry.go:36 +0x50
github.com/pocketbase/pocketbase/daos.(*Dao).lockRetry(0x14000630360?, 0x1400012ddc0?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:327 +0x4c
github.com/pocketbase/pocketbase/daos.(*Dao).Save(0x140008187d0?, {0x1029e4918, 0x140001c1b20})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:228 +0xa0
github.com/pocketbase/pocketbase/daos.(*Dao).SaveRecord(0x140008e89b8?, 0x140001c1b20?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/record.go:416 +0x110
github.com/pocketbase/pocketbase/forms.(*RecordUpsert).Submit.func1(0x10?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/forms/record_upsert.go:777 +0x1c0
github.com/pocketbase/pocketbase/forms.runInterceptors[...](0x1012ba224?, 0x60?, {0x0?, 0x1027a8940, 0x14000594600?})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/forms/base.go:30 +0x64
github.com/pocketbase/pocketbase/forms.(*RecordUpsert).Submit(0x14000e01d40, {0x0, 0x0, 0x0})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/forms/record_upsert.go:735 +0x90
main.main.func1(0x1400083f908)
	/Users/plorenzo/dev/gorkspace/src/gitlab.com/azabache/troco-io/troco-app/main.go:46 +0x1d0
github.com/pocketbase/pocketbase/tools/hook.(*TaggedHook[...]).Add.func1()
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/tools/hook/tagged.go:69 +0x6c
github.com/pocketbase/pocketbase/tools/hook.(*Hook[...]).Trigger(0x1029e2780, 0x14000e01c80, {0x0?, 0x0, 0x10086619c})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/tools/hook/hook.go:65 +0x230
github.com/pocketbase/pocketbase/core.(*BaseApp).createDaoWithHooks.func2(0x140003c1f20, {0x1029e4918?, 0x140001c1b20})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/core/base.go:986 +0xc8
github.com/pocketbase/pocketbase/daos.(*Dao).create(0x140003c1f20, {0x1029e4918, 0x140001c1b20})
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:318 +0x2b4
github.com/pocketbase/pocketbase/daos.(*Dao).Save.func1(0x0?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:224 +0x24
github.com/pocketbase/pocketbase/daos.(*Dao).lockRetry.func1(0x140008e8d88?)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base.go:337 +0x188
github.com/pocketbase/pocketbase/daos.baseLockRetry(0x140008e8dc8, 0x8)
	/Users/plorenzo/dev/gorkspace/pkg/mod/github.com/pocketbase/pocketbase@v0.14.4/daos/base_retry.go:36 +0x50
github.com/pocketbase/pocketbase/daos.(*Dao).lockRetry(0x14000225e60?, 0x1400012cee0?)

I'm guessing it has to do with some recent change in a new release, but can't find the issue.

I use an OnModelAfterCreate() hook:

// Adds default avatar image after user creation
	app.OnModelAfterCreate().Add(func(e *core.ModelEvent) error {

		if e.Model.TableName() == "users" {
			path := "./ui/static/img/user.png"
			file, err := filesystem.NewFileFromPath(path)
			if err != nil {
				return err
			}

			form := forms.NewRecordUpsert(app, e.Model.(*models.Record))
			form.SetDao(daos.New(app.Dao().DB()))
			form.AddFiles("avatar", file)

			return form.Submit()
		}
		return nil
	})

I tried deleting pb_data and start from scratch with the same results.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions