Skip to content

[FIX][base_import_match] Avoid UnicodeEncodeError. - #544

Merged
moylop260 merged 4 commits into
OCA:8.0from
Tecnativa:8.0-base_import_match-fix_ascii
Sep 20, 2016
Merged

[FIX][base_import_match] Avoid UnicodeEncodeError.#544
moylop260 merged 4 commits into
OCA:8.0from
Tecnativa:8.0-base_import_match-fix_ascii

Conversation

@yajo

@yajo yajo commented Sep 7, 2016

Copy link
Copy Markdown
Member

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 15: ordinal not in range(128).

Now, using unicode strings, that won't happen again.

Also fix wrong README format.

@Tecnativa

@pedrobaeza

Copy link
Copy Markdown
Member

👍

@yajo

yajo commented Sep 7, 2016

Copy link
Copy Markdown
Member Author

Travis ❌ unrelated

@moylop260

Copy link
Copy Markdown
Contributor

FYI We have a open discussion of this matter OCA/pylint-odoo#65
Your feedback is welcome.

@lasley

lasley commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

Ahhh good ol' unicode 👍

@moylop260

moylop260 commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

👍 (just small comments)

Comment thread base_import_match/models/base_import.py Outdated
s.name = u"{}: {}".format(
s.model_id.display_name,
" + ".join(
u" + ".join(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This u is not required.
Just in the format sentence is required.

@yajo

yajo commented Sep 8, 2016

Copy link
Copy Markdown
Member Author

Trying different (I think it is better) approach.

Comment thread base_import_match/models/base_import.py Outdated
s.field_ids.mapped(
lambda r: (
str(r.field_id.name) +
unicode(r.field_id.name) +

@moylop260 moylop260 Sep 8, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

odoo returns a unicode string here then we don't need a unicode(string_unicode) again.
The problem is use "{}".format() instead of u"{}".format() (Notice the u prefix)

@moylop260 moylop260 Sep 8, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

u'%s' % u'á'  # without error
'%s' % u'á'  # without error

u'{}'.format(u'á')  # without error
'{}'.format(u'á')  # UnicodeEncodeError

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think you don't get the point. I have to use unicode because otherwise if r.field_id.name is False this would blow.

@moylop260 moylop260 Sep 9, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean,

odoo returns a unicode string then we don't need a unicode(string_unicode) again...

for all strings returned.

We could use string_unicode or 'None' just for None cases avoiding additional re-processing of unicode method.

@lasley lasley Sep 9, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed, method calls in Python are more expensive than boolean evaluations - so the proposed my_field and u'{}'.format(my_field) or my_field would be ideal even though more code. Although I bet there's a cleaner fallback strategy too...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I double-checked, and after all name and field_id are required, so no chance of getting False. I'll just drop casting.

@yajo
yajo force-pushed the 8.0-base_import_match-fix_ascii branch from ce7b13e to dec4c3f Compare September 20, 2016 09:29
yajo and others added 4 commits September 20, 2016 11:32
When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.
@yajo
yajo force-pushed the 8.0-base_import_match-fix_ascii branch from dec4c3f to 0170f56 Compare September 20, 2016 09:33
@yajo

yajo commented Sep 20, 2016

Copy link
Copy Markdown
Member Author

Finally 💚 !

@moylop260

Copy link
Copy Markdown
Contributor

👍 thanks

@moylop260
moylop260 merged commit 3558676 into OCA:8.0 Sep 20, 2016
@yajo
yajo deleted the 8.0-base_import_match-fix_ascii branch September 20, 2016 13:28
cubells pushed a commit to Tecnativa/server-tools that referenced this pull request Dec 15, 2016
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
cubells pushed a commit to Tecnativa/server-tools that referenced this pull request Dec 15, 2016
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
nicomacr pushed a commit to adhoc-dev/server-tools that referenced this pull request Dec 16, 2016
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
pedrobaeza pushed a commit to Tecnativa/server-tools that referenced this pull request Dec 17, 2016
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
yajo added a commit to Tecnativa/server-tools that referenced this pull request Jun 22, 2017
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
pedrobaeza pushed a commit to Tecnativa/server-tools that referenced this pull request Aug 16, 2017
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
lasley pushed a commit to LasLabs/server-tools that referenced this pull request Aug 29, 2017
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (12.0)
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.

4 participants