File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed
Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -528,15 +528,11 @@ def deserialize(byts):
528528
529529 @staticmethod
530530 def serialize (ustr ):
531- # ustr.encode('utf8') fails when the string is already encoded
532- # this is common if your data comes through other database drivers (e.g. odbc, psycopg2, etc.)
533- if isinstance (ustr , unicode ): # check type explicitly. Unicode will encode successfuly.
534- return ustr .encode ('utf8' )
535- # otherwise, our input string is either already encoded or not unicode to begin with.
536- # since all cassandra strings are utf-8, we can validate that the ustr is already encoded utf-8 by decoding it
537- else :
538- ustr .decode ('utf-8' ) # will raise UnicodeDecodeError if not utf8 encoded byte string.
539- return ustr # definitely valid :)
531+ try :
532+ return ustr .encode ('utf-8' )
533+ except UnicodeDecodeError :
534+ # already utf-8
535+ return ustr
540536
541537
542538class VarcharType (UTF8Type ):
You can’t perform that action at this time.
0 commit comments