[FIX][base_import_match] Avoid UnicodeEncodeError. - #544
Conversation
|
👍 |
|
Travis ❌ unrelated |
|
FYI We have a open discussion of this matter OCA/pylint-odoo#65 |
|
Ahhh good ol' unicode 👍 |
|
👍 (just small comments) |
| s.name = u"{}: {}".format( | ||
| s.model_id.display_name, | ||
| " + ".join( | ||
| u" + ".join( |
There was a problem hiding this comment.
This u is not required.
Just in the format sentence is required.
|
Trying different (I think it is better) approach. |
| s.field_ids.mapped( | ||
| lambda r: ( | ||
| str(r.field_id.name) + | ||
| unicode(r.field_id.name) + |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
u'%s' % u'á' # without error
'%s' % u'á' # without error
u'{}'.format(u'á') # without error
'{}'.format(u'á') # UnicodeEncodeErrorThere was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
I double-checked, and after all name and field_id are required, so no chance of getting False. I'll just drop casting.
ce7b13e to
dec4c3f
Compare
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.
dec4c3f to
0170f56
Compare
|
Finally 💚 ! |
|
👍 thanks |
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
Syncing from upstream OCA/server-tools (12.0)
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