GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: handle failed database inserts in DatabaseHandler::push() by gr8man · Pull Request #103 · codeigniter4/queue

Conversation

@gr8man

@gr8man gr8man commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Description

DatabaseHandler::push() assumed that Model::insert() always returns a job ID. In reality Model::insert() returns int|string|false and returns false when the insert cannot be performed (for example, when the statement fails or a beforeInsert callback aborts it).

Because the guard only checked $jobId === 0, a false return value fell through to QueuePushResult::success($jobId), whose parameter is declared as int. That raised a TypeError instead of returning a proper failure result, and the queue:jobPushed event was emitted for a job that was never stored.

Changes

  • src/Handlers/DatabaseHandler.php
    • Treat false, 0 and non-numeric values as a failed insert: emit queue:jobPushFailed and return QueuePushResult::failure('Failed to insert job into the database.').
    • Cast the accepted job ID to int before assigning it to the QueueJob entity and before calling QueuePushResult::success(), so the value always matches the declared types.

Testing

Added two cases to tests/DatabaseHandlerTest.php:

  • testPushWhenModelReturnsFalse() — a false return from the model produces a failed result with the expected error message and no job ID, does not emit queue:jobPushed and does emit queue:jobPushFailed.
  • testPushWhenModelReturnsZero() — 0 keeps the previous behaviour (failure result, jobPushFailed emitted, no jobPushed).

Both tests use an event-listener reset in tearDown() so the events of one test cannot leak into another.

Verified locally on PHP 8.5 with PHPUnit 11.5:

phpunit ....... OK (232 tests, 659 assertions, 27 skipped)
phpstan ....... [OK] No errors
psalm ......... No errors found
php-cs-fixer .. 0 of 75 files would be fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gr8man added 2 commits November 10, 2026 21:34
@gr8man
fix: handle failed database inserts in DatabaseHandler::push()
8d638a4
@gr8man
test: add tests for DatabaseHandler::push() when model returns false …
1d745ef
…or 0

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@gr8man
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.