-
Notifications
You must be signed in to change notification settings - Fork 0
fix(print): PrintOptions.copies replicates images for hardware print #115
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Bug: Duplicate
job_idswill be skipped by the queue workerWhile this change correctly replicates the images and job IDs to pass the length validation in
enqueue_batch, it introduces a critical bug during the actual printing process inPrintQueue._process_batch(defined inbackend/app/services/print_queue.py).In
_process_batch, the worker iterates overbatch.job_idsand attempts to transition each job to thePRINTINGstate:Because
expanded_job_idscontains duplicate UUIDs for copies,self._jobs.get(str(jid))retrieves the exact same in-memoryJobinstance for all copies of a request.idx = 0), the job transitions fromQUEUEDtoPRINTINGsuccessfully, and0is added toactive_indices.idx > 0), the job is already in thePRINTINGstate. CallingJobStateMachine.transition(job, JobState.PRINTING)raises anInvalidStateTransitionError.exceptblock and skipped, meaning their indices are never added toactive_indices.As a result,$N$ copies.
active_payloadswill only contain the first copy's image, and the printer will still only print one single label instead ofWhy did the tests pass?
The unit tests in
test_print_service.pymockqueue.enqueue_batchand only assert that the arguments passed to it are correct. They do not run the actual queue worker loop (_process_batch), which is why this integration bug went unnoticed.Recommended Solution
To fix this, we need to update
_process_batchinbackend/app/services/print_queue.pyto allow processing duplicate job IDs without raising state transition errors, and deduplicate them during final state transitions (likeCOMPLETEDorFAILED).In
backend/app/services/print_queue.py(_process_batch):Allow duplicate jobs to bypass the transition if they are already
PRINTING:Deduplicate transitions to terminal states (
COMPLETED/FAILED):