Skip to content

UnexpectedError DataError: 1366 Incorrect string value #747

@goulu

Description

@goulu

I try to store translations in many languages and get this error :

pony.orm.core.UnexpectedError: Object Label['𑂓𑂳𑂗𑂹𑂗𑂲','bho'] cannot be stored in the database. DataError: 1366 Incorrect string value: '\xF0\x91\x82\x93\xF0\x91...' for column 'label' at row 1
the database Is MySQL latest.
the class is

class Label(db.Entity):
    label = Required(
        str, sql_type="VARCHAR(255) CHARACTER SET \'utf8mb4\' COLLATE \'utf8mb4_general_ci\'", index='labels')
    lang = Required(str, 10)
    PrimaryKey(label, lang)

I specified the CHARACTER SET and COLLATE after trying different combinations which gave the same error

What's more disturbing is that the error is not trapped in my code, which could allow to skip some rare languages:

@db_session
def add(label: str, lang=DEFAULT) -> Label:
    if not label:
        return None
    lang = lang or DEFAULT
    try:
        return Label[label, lang]
    except:
        pass
    try:
        return Label(label=label, lang=lang)
    except:
        return None  

actually, it seems the error occurs later, when closing the session (see dump attached)

Traceback.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions