Skip to content

V1 schedule.onRun doesn't call onInit #1680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tecbot opened this issue Mar 19, 2025 · 6 comments
Open

V1 schedule.onRun doesn't call onInit #1680

tecbot opened this issue Mar 19, 2025 · 6 comments
Labels

Comments

@tecbot
Copy link

tecbot commented Mar 19, 2025

firebase-functions: 6.3.2

If creating a schedule.onRun function, onInit is not called because of this lines:

Will set label deployment-scheduled to true

labels: { "deployment-scheduled": "true" },

makeCloudFunction is wrapping withInit on the first line

handler = withInit(handler ?? contextOnlyHandler);

However, because of the deployment-scheduled label it uses the non wrapped handler:

promise = contextOnlyHandler(context);

Expected behavior

onInit callback is called

Actual behavior

onInit is not called and causes issues with the function execution

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@CorieW
Copy link
Contributor

CorieW commented Mar 20, 2025

Hi @tecbot,

Thanks for reporting this issue! We’ve received it and are reviewing it. We’ll provide updates as soon as possible.

@CorieW
Copy link
Contributor

CorieW commented Mar 20, 2025

If you have time, could you produce some code that demonstrates this issue?

@CorieW CorieW added triaged Triaged and removed needs-triage labels Mar 20, 2025
@tecbot
Copy link
Author

tecbot commented Mar 20, 2025

I already referenced the misleading code lines. Creating a v1 pubsub trigger will cause the issue always:

import { onInit } from 'firebase-functions'
import * as functions from 'firebase-functions/v1'
import { info } from 'firebase-functions/logger'

onInit(() => {
     info("onInit called")
})

export const myFunction = functions
    .pubsub.schedule('*/10 * * * *')
    .onRun(() => {
        info("function executed")
    })

Expected log output:

  • onInit called
  • function executed

Actual:

  • function executed

@CorieW
Copy link
Contributor

CorieW commented Mar 20, 2025

Appreciate it! It's just so whoever picks this up can easily reproduce and also use it to verify their fix works.

@CorieW
Copy link
Contributor

CorieW commented Mar 21, 2025

Reproduced

@CorieW CorieW added the reproducible: yes Issue with a repro label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants