Skip to content

Update packtools to 4.16.1 to fix thumbnail creation error#496

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-packtools-optimiser-error
Draft

Update packtools to 4.16.1 to fix thumbnail creation error#496
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-packtools-optimiser-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

O que esse PR faz?

Atualiza packtools de 2.9.5 para 4.16.1, corrigindo o ValueError: image has wrong mode que ocorre ao gerar miniaturas de imagens com modos incompatíveis (P, CMYK, I, F, etc.) durante a otimização de pacotes SPS.

Onde a revisão poderia começar?

requirements.txt — única alteração.

Como este poderia ser testado manualmente?

Processar um pacote SPS contendo imagens com modo P (paleta) ou CMYK e verificar que o optimize_package_task_id completa sem erro.

Algum cenário de contexto que queira dar?

O PIL não suporta thumbnail()/resize() com resampler LANCZOS em imagens com certos modos de cor. O packtools 4.16.1 converte a imagem para RGB/RGBA antes do resize, resolvendo o problema na raiz.

ValueError: image has wrong mode
  File "packtools/utils.py", line 421, in get_thumbnail_bytes
    self._image_object.thumbnail(self.thumbnail_size)

Screenshots

N/A

Quais são tickets relevantes?

scieloorg/ajuda#15

Referências

Original prompt

This section details on the original issue you should resolve

<issue_title>Erro do optimiser do packtools ao criar miniatura</issue_title>
<issue_description>### Descrição do problema

O packtools foi corrigido. Use a versão 4.16.1.

obtive isso ao usar optimiser do packtools [2026-01-09 21:58:44,242] {taskinstance.py:901} INFO - Executing <Task(ShortCircuitOperator): optimize_package_task_id> on 2026-01-09T20:31:57.066931+00:00
[2026-01-09 21:58:44,250] {standard_task_runner.py:54} INFO - Started process 4137959 to run task
[2026-01-09 21:58:44,348] {standard_task_runner.py:77} INFO - Running: ['airflow', 'run', 'sync_documents_to_kernel', 'optimize_package_task_id', '2026-01-09T20:31:57.066931+00:00', '--job_id', '405724', '--pool', 'default_pool', '--raw', '-sd', 'DAGS_FOLDER/sync_documents_to_kernel.py', '--cfg_path', '/tmp/tmpp8qn7kqa']
[2026-01-09 21:58:44,352] {standard_task_runner.py:78} INFO - Job 405724: Subtask optimize_package_task_id
[2026-01-09 21:58:44,750] {logging_mixin.py:112} INFO - Running %s on host %s <TaskInstance: sync_documents_to_kernel.optimize_package_task_id 2026-01-09T20:31:57.066931+00:00 [running]> airflow-778f6d87b4-t6sx2
[2026-01-09 21:58:44,979] {utils.py:792} INFO - Generating new SciELO Publishing Package /tmp/tmpa1r6o4ki/2026-01-05-13-30-59-496018_bjos_v24.zip
[2026-01-09 21:58:44,980] {utils.py:803} INFO - Optimizing XML file 1677-3225-bjos-24-e256503.xml [0/1]
[2026-01-09 21:58:45,778] {taskinstance.py:1150} ERROR - image has wrong mode
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 984, in _run_raw_task
    result = task_copy.execute(context=context)
  File "/usr/local/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 158, in execute
    condition = super(ShortCircuitOperator, self).execute(context)
  File "/usr/local/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 113, in execute
    return_value = self.execute_callable()
  File "/usr/local/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 118, in execute_callable
    return self.python_callable(*self.op_args, **self.op_kwargs)
  File "/usr/local/airflow/dags/sync_documents_to_kernel.py", line 95, in optimize_package
    _sps_package, new_sps_zip_dir
  File "/usr/local/airflow/dags/operations/sync_documents_to_kernel_operations.py", line 136, in optimize_sps_pkg_zip_file
    preserve_files=False
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 807, in optimise
    new_package_file_path, xml_filename, zipped_filenames
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 714, in _optimise_to_zipfile
    optimised_xml = xml_web_optimiser.get_xml_file()
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 636, in get_xml_file
    image_filename, self._add_assets_thumbnails
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 600, in _get_optimised_image_with_filename
    return add_image(image_filename)
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 570, in _add_assets_thumbnails
    thumbnail_bytes = web_image_generator.get_thumbnail_bytes()
  File "/usr/local/lib/python3.7/site-packages/packtools/utils.py", line 421, in get_thumbnail_bytes
    self._image_object.thumbnail(self.thumbnail_size)
  File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2619, in thumbnail
    im = self.resize(size, resample, box=box, reducing_gap=reducing_gap)
  File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2193, in resize
    return self._new(self.im.resize(size, resample, box))
ValueError: image has wrong mode
[2026-01-09 21:58:45,801] {taskinstance.py:1194} INFO - Marking task as FAILED. dag_id=sync_documents_to_kernel, task_id=optimize_package_task_id, execution_date=20260109T203157, start_date=20260109T215843, end_date=20260109T215845
[2026-01-09 21:58:48,871] {local_task_job.py:102} INFO - Task exited with return code 1

Passos para reproduzir o problema

  1. Acesse a página ...
  2. Clique no link ...
  3. Role a página até ...
  4. Observe o erro apresentado

Comportamento esperado

...

Screenshots ou vídeos

n/a

Anexos

scieloorg/ajuda#15

Ambiente utilizado

opac-airflow v1.0.0-rc84

Diagnóstico

Análise do Erro

O erro ValueError: image has wrong mode ocorre no PIL/Pillow ao tentar redimensionar uma imagem para gerar o thumbnail. Isso geralmente acontece quando a imagem está em um modo não suportado para resize com certos resamplers — como modo P (paleta/indexed), CMYK, LA, ou I (32-bit integers).

O problema está em packtools/utils.py, linha 421:

self._image_object.thumbnail(self.thumbnail_size)

Causa Raiz

O PIL não consegue fazer resize com LANCZOS (ou outros res...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…n error

Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix optimiser error in packtools when creating thumbnail Update packtools to 4.16.1 to fix thumbnail creation error Mar 11, 2026
@robertatakenaka robertatakenaka requested a review from Copilot March 11, 2026 17:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Erro do optimiser do packtools ao criar miniatura

3 participants