Skip to content

MySQL result backend defaults to BLOB which may be too short for some results (LONGBLOB) #461

Open

Description

I was running into errors caused by loading truncated pickled results. Specifically, I would get an EOFError (see below). I eventually figured out that the result column of the celery_taskmeta MySQL table was not able to hold all of the pickled result data. By altering the table to use LONGBLOB instead of BLOB, I was able to deal with the large results (alter table celery_taskmeta modify result LONGBLOB). Is there a way to make this the default type in the future?

[2011-08-31 13:34:13,605: ERROR/PoolWorker-1] 
Traceback (most recent call last):
  File "/home/ubuntu/w/apis/trunk/apis/celerytasks/tasks/file_task_base.py", line 293, in process
    self.process_records()
  File "/home/ubuntu/w/apis/trunk/apis/celerytasks/tasks/proxmatch_file.py", line 381, in process_records
    self.wait_results(async_result_buffer)
  File "/home/ubuntu/w/apis/trunk/apis/celerytasks/tasks/proxmatch_file.py", line 435, in wait_results
    async_result.wait()
  File "/usr/local/lib/python2.6/dist-packages/celery/result.py", line 87, in wait
    return self.get(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/celery/result.py", line 83, in get
    interval=interval)
  File "/usr/local/lib/python2.6/dist-packages/celery/backends/base.py", line 110, in wait_for
    status = self.get_status(task_id)
  File "/usr/local/lib/python2.6/dist-packages/celery/backends/base.py", line 206, in get_status
    return self.get_task_meta(task_id)["status"]
  File "/usr/local/lib/python2.6/dist-packages/celery/backends/base.py", line 227, in get_task_meta
    meta = self._get_task_meta_for(task_id)
  File "/usr/local/lib/python2.6/dist-packages/celery/backends/database.py", line 61, in _get_task_meta_for
    task = session.query(Task).filter(Task.task_id == task_id).first()
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py", line 1770, in first
    ret = list(self[0:1])
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py", line 1667, in __getitem__
    return list(res)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py", line 1960, in instances
    rows = [process[0](row, None) for row in fetch]
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 2600, in _instance
    populate_state(state, dict_, row, isnew, only_load_props)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 2454, in populate_state
    populator(state, dict_, row)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/strategies.py", line 150, in new_execute
    dict_[key] = row[col]
  File "/usr/local/lib/python2.6/dist-packages/celery/db/a805d4bd.py", line 55, in process
    return loads(value)
EOFError

Activity

  1. ask commented on Aug 31, 2011

    @ask
    Contributor

    I think we'd prioritise small results first, as this is the most common use case, but if a blob is not big enough to hold
    "reasonably" sized results, then longblob wold be a good default.

    Could we find out the current limit for blobs in mysql? What are the space implications for smaller results?

  2. ask commented on Sep 1, 2011

    @ask
    Contributor

    Yeah, I know about strict mode, that it's not enabled by default is kind of unique to MySQL, and often criticised.
    It's one of the first things I enable on new MySQL installs.

    16bits is very small indeed, we should definitely increase that.

    It seems that a BLOB in Oracle is 2**32 by default: http://ss64.com/ora/syntax-datatypes.html
    In PostgreSQL it seems that the bytea type is preferred, and that it is of unlimited size. Maybe
    BLOB maps to this field directly. I couldn't find any information about whether any of the SQL standards
    describe dimensions for the BLOB field type.

    django-celery uses django-picklefield, and pickled data is stored in a text field
    there: https://github.com/shrubberysoft/django-picklefield/blob/master/src/picklefield/fields.py
    I checked django.db.backends.mysql.creation and TextFields uses LONGTEXT on MySQL.

    picklefield also uuencodes the data though, and there is an issue open for the sqlalchemy backend to use the same
    method so the backends can be interchangeable: #183

    I think maybe we should resolve issue #183 at the same time so we don't have to change the types that often.
    Which means changing the BLOB to be a LONGTEXT

  3. ask commented on Aug 30, 2012

    @ask
    Contributor

    On further inspection this is behavior from SQLAlchemy, where sqlalchemy.types.PickleType is a LargeBinary field that resolves to a BLOB when using MYSQL. Sadly there is no generic data type in sqlalchemy that is larger than a LargeBlob and so if we used a LARGE_BLOB it would not be compatible with all other supported databases.

    I think sqlalchemy must be lobbied to change the default large binary type for MySQL, or people depending on large results must alter the table :(

  4. removed this from the milestone on Jan 13, 2018
  5. ericraymond commented on Nov 28, 2018

    @ericraymond

    Is there a resolution on this before it was closed?

  6. georgepsarakis commented on Nov 29, 2018

    @georgepsarakis
    Contributor

    @ericraymond the database result backend still uses PickleType, which maps to a LargeBinary field in SQLAlchemy as far as I can tell. I suggest that you review the previous comments and if you can provide or propose a solution please feel free to open a new issue.

  7. ericraymond commented on Nov 29, 2018

    @ericraymond

    @georgepsarakis I see your point.

    Celery could directly use the MySQL longblob type but that would break the abstraction that Celery uses sqlalchemy for multiple database dialects. The other alternatives are for SQLAlchemy to change the MySQL dialect mapping or create a new (largeblob) MySQL Dialect.

  8. georgepsarakis commented on Nov 30, 2018

    @georgepsarakis
    Contributor

    @ericraymond I think I came up with a possible solution. We can redefine the field as LargeBinary and handle the pickling part separately (before storing the result). From the documentation, you can pass a length parameter to the field definition, which MySQL will then map to the corresponding type (MEDIUMBLOB, LONGBLOB) that can contain binary strings of this length:

    -- Set the maximum length to 4GB
    mysql> CREATE TABLE results(serialized_result BLOB(4294967295));
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> SHOW CREATE TABLE results\G
    *************************** 1. row ***************************
           Table: results
    Create Table: CREATE TABLE `results` (
      `serialized_result` longblob
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1
    1 row in set (0.00 sec)
    

    What do you think?

  9. ericraymond commented on Nov 30, 2018

    @ericraymond
  10. added this to the v5.0.0 milestone on Dec 4, 2018
  11. removed this from the v5.0.0 milestone on Apr 4, 2019
  12. 17 remaining items

  13. modified the milestones: 5.1.0, 5.2 on May 4, 2021
  14. ericraymond commented on Aug 11, 2021

    @ericraymond

    Is this part of 5.2?

  15. thedrow commented on Aug 17, 2021

    @thedrow
    Contributor

    I'm sorry I couldn't get to this in 5.1.
    I'm hoping I'll have time to finish this by 5.2.

  16. modified the milestones: 5.2, 5.3 on Oct 31, 2021
  17. removed this from the 5.3 milestone on Feb 19, 2023
  18. alexpotv commented on Aug 19, 2024

    @alexpotv

    Commenting to show interest! For now, I've bypassed this feature by manually adjusting the column type in my migration files, but would really love to see it implemented!

  19. mvhconsult commented on Jan 31, 2025

    @mvhconsult

    Any progress? I am trying out a sql backend (MariaDB) but most tasks now fail due to this storage size.

  20. auvipy commented on Feb 1, 2025

    @auvipy
    Member

    I will revisit this after celery 5.5 release

  21. added this to the 5.7.0 milestone on May 19, 2025
  22. modified the milestones: 5.7.0, 5.8.0 on Aug 26, 2026
  23. APX403 commented on Nov 27, 2026

    @APX403

    Still happens on main (22be744) with MariaDB 10.11 in its default strict mode: a task returning 70,000 bytes ends in FAILURE with Data too long for column 'result', and GroupResult.save() with 1,200 results fails the same way. Since #10536 the column holds the configured serializer's output in a LargeBinary, so a LONGBLOB variant for the mysql and mariadb dialects, as DialectSpecificInteger does for MSSQL, would fix new tables, with a note in the docs giving the ALTER TABLE for existing ones. Would you take a PR for that?

  24. auvipy commented on Nov 28, 2026

    @auvipy
    Member

    Still happens on main (22be744) with MariaDB 10.11 in its default strict mode: a task returning 70,000 bytes ends in FAILURE with Data too long for column 'result', and GroupResult.save() with 1,200 results fails the same way. Since #10536 the column holds the configured serializer's output in a LargeBinary, so a LONGBLOB variant for the mysql and mariadb dialects, as DialectSpecificInteger does for MSSQL, would fix new tables, with a note in the docs giving the ALTER TABLE for existing ones. Would you take a PR for that?

    @ghirailghiro can you check this?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions