Skip to content

chore: enforce that pop.SetNowFunc only can be called inside init()#13

Merged
gaultier merged 4 commits intomainfrom
pgaultier-enforce-setnowfunc-only-in-init
Dec 3, 2025
Merged

chore: enforce that pop.SetNowFunc only can be called inside init()#13
gaultier merged 4 commits intomainfrom
pgaultier-enforce-setnowfunc-only-in-init

Conversation

@gaultier
Copy link

@gaultier gaultier commented Dec 3, 2025

When the function is not called inside init(), it looks like this:

--- FAIL: Test_Create_Timestamps_With_NowFunc (0.00s)
panic: caller init() not found in call stack, reached end of call stack [recovered, repanicked]

goroutine 616 [running]:
testing.tRunner.func1.2({0x10142a0a0, 0x10159bfc0})
	/opt/homebrew/Cellar/go/1.25.4/libexec/src/testing/testing.go:1872 +0x2b4
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.25.4/libexec/src/testing/testing.go:1875 +0x460
panic({0x10142a0a0?, 0x10159bfc0?})
	/opt/homebrew/Cellar/go/1.25.4/libexec/src/runtime/panic.go:783 +0x120
github.com/ory/pop/v6.ensuredCalledInsideInit()
	/Users/philippe.gaultier/company-code/pop/model.go:40 +0x200
github.com/ory/pop/v6.SetNowFunc(...)
	/Users/philippe.gaultier/company-code/pop/model.go:48
github.com/ory/pop/v6.Test_Create_Timestamps_With_NowFunc.func1(0xc0004dcd80)
	/Users/philippe.gaultier/company-code/pop/executors_test.go:2007 +0x198
github.com/ory/pop/v6.transaction.func1(0xc0004dcd80)
	/Users/philippe.gaultier/company-code/pop/pop_test.go:73 +0x3c
github.com/ory/pop/v6.(*Connection).Rollback(0xc0000aaae0, 0xc00004be50)
	/Users/philippe.gaultier/company-code/pop/connection.go:196 +0x124
github.com/ory/pop/v6.transaction(0xc0005efe98)
	/Users/philippe.gaultier/company-code/pop/pop_test.go:72 +0x68
github.com/ory/pop/v6.Test_Create_Timestamps_With_NowFunc(0xc0004c0700)
	/Users/philippe.gaultier/company-code/pop/executors_test.go:1997 +0xa4
testing.tRunner(0xc0004c0700, 0x101599500)
	/opt/homebrew/Cellar/go/1.25.4/libexec/src/testing/testing.go:1934 +0x168
created by testing.(*T).Run in goroutine 1
	/opt/homebrew/Cellar/go/1.25.4/libexec/src/testing/testing.go:1997 +0x6e4
FAIL	github.com/ory/pop/v6	1.494s

which is why Test_Create_Timestamps_With_NowFunc was removed in this PR.

Tested successfully in kratos/kratos-oss.

@gaultier gaultier self-assigned this Dec 3, 2025
@gaultier gaultier requested a review from a team as a code owner December 3, 2025 14:48
@gaultier gaultier marked this pull request as draft December 3, 2025 14:52
@gaultier gaultier marked this pull request as ready for review December 3, 2025 15:05
@gaultier gaultier merged commit a322338 into main Dec 3, 2025
8 checks passed
@gaultier gaultier deleted the pgaultier-enforce-setnowfunc-only-in-init branch December 3, 2025 15:22
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