Skip to content

Never seen error upon Python dict insertion into RethinkDB 1.13,3 #2699

Closed

Description

@murphsp1

Inserting the following Python DICT (right after an upgrade to 1.13,3) resulted in the error at the bottom.

{u'contributors_enabled': False,
u'created_at': u'Mon May 19 16:47:46 +0000 2008',
u'default_profile': True,
u'default_profile_image': True,
u'description': u'Get a FREE DVD & brochures on buying a property in Paphos, Cyprus',
u'entities': {u'description': {u'urls': []},
u'url': {u'urls': [{u'display_url': u'all-destinations.com/buy_cyprus_pro\u2026',
u'expanded_url': u'http://www.all-destinations.com/buy_cyprus_property.htm',
u'indices': [0, 22],
u'url': u'http://t.co/mPAhFDHGFD'}]}},
u'favourites_count': 0,
u'follow_request_sent': False,
u'followers_count': 42,
u'following': False,
u'friends_count': 309,
u'geo_enabled': False,
u'id': 14834835,
u'id_str': u'14834835',
u'is_translation_enabled': False,
u'is_translator': False,
u'lang': u'en',
u'listed_count': 0,
u'location': u'',
u'name': u'Dante',
u'notifications': False,
u'profile_background_color': u'C0DEED',
u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png',
u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png',
u'profile_background_tile': False,
u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png',
u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png',
u'profile_link_color': u'0084B4',
u'profile_sidebar_border_color': u'C0DEED',
u'profile_sidebar_fill_color': u'DDEEF6',
u'profile_text_color': u'333333',
u'profile_use_background_image': True,
u'protected': False,
u'screen_name': u'prope3c7',
u'status': {u'contributors': None,
u'coordinates': None,
u'created_at': u'Mon Jun 02 12:11:30 +0000 2008',
u'entities': {u'hashtags': [],
u'symbols': [],
u'urls': [],
u'user_mentions': []},
u'favorite_count': 0,
u'favorited': False,
u'geo': None,
u'id': 825129908,
u'id_str': u'825129908',
u'in_reply_to_screen_name': None,
u'in_reply_to_status_id': None,
u'in_reply_to_status_id_str': None,
u'in_reply_to_user_id': None,
u'in_reply_to_user_id_str': None,
u'lang': u'en',
u'place': None,
u'retweet_count': 0,
u'retweeted': False,
u'source': u'Twitter Web Client',
u'text': u"Cyprus finally won its' independence in 1960 under Archbishop Makarios. h\x00t\x00t\x00p\x00:\x00/\x00/\x00w\x00w\x00w\x00\x00\x00\x00\x00\x00\x00\x0e\x00D\x00a\x00r\x00r\x00y\x00l\x00 \x00A\x00n\x00t\x00o\x00n\x00i\x00o\x00\x0e\x00D\x00a\x00r\x00 ...",
u'truncated': False},
u'statuses_count': 23,
u'time_zone': u'Mountain Time (US & Canada)',
u'url': u'http://t.co/mPAhFDHGFD',
u'utc_offset': -21600,
u'verified': False}

Resulted in the following error:
RqlClientError Traceback (most recent call last)
in ()
1 for tp in twitter_profiles:
----> 2 temp = rdb.db(DB_NAME).table(tablename).insert(tp).run(CONNECTION)
3 print temp

/Library/Python/2.7/site-packages/rethinkdb/ast.pyc in run(self, c, *_global_optargs)
73 raise RqlDriverError("RqlQuery.run must be given a connection to run on.")
74
---> 75 return c._start(self, *_global_optargs)
76
77 def str(self):

/Library/Python/2.7/site-packages/rethinkdb/net.pyc in _start(self, term, **global_optargs)
211 self.next_token += 1
212
--> 213 return self._send_query(query, global_optargs)
214
215 def _handle_cursor_response(self, response):

/Library/Python/2.7/site-packages/rethinkdb/net.pyc in _send_query(self, query, opts, async)
312 # Get response
313 response = self._read_response(query.token)
--> 314 self._check_error_response(response, query.term)
315
316 if response.type == pResponse.SUCCESS_PARTIAL or \

/Library/Python/2.7/site-packages/rethinkdb/net.pyc in _check_error_response(self, response, term)
293 message = response.data[0]
294 frames = response.backtrace
--> 295 raise RqlClientError(message, term, frames)
296
297 def _send_query(self, query, opts={}, async=False):

RqlClientError: RqlClientError: Client is buggy (failed to deserialize query). in:
r.db('social_rudder').table('mississippi_master_emails_06_22_2014_TwitterNetwork_Profiles').insert(r.expr({u'follow_request_sent': False, u'profile_use_background_image': True, u'id': 14834835, u'verified': False, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png', u'profile_sidebar_fill_color': u'DDEEF6', u'is_translator': False, u'entities': r.expr({u'url': r.expr({u'urls': [r.expr({u'url': u'http://t.co/mPAhFDHGFD', u'indices': [0, 22], u'expanded_url': u'http://www.all-destinations.com/buy_cyprus_property.htm', u'display_url': u'all-destinations.com/buy_cyprus_pro\u2026'})]}), u'description': r.expr({u'urls': []})}), u'followers_count': 42, u'protected': False, u'location': u'', u'default_profile_image': True, u'id_str': u'14834835', u'status': r.expr({u'lang': u'en', u'favorited': False, u'contributors': None, u'truncated': False, u'source': u'Twitter Web Client', u'text': u"Cyprus finally won its' independence in 1960 under Archbishop Makarios. h\x00t\x00t\x00p\x00:\x00/\x00/\x00w\x00w\x00w\x00\x00\x00\x00\x00\x00\x00\x0e\x00D\x00a\x00r\x00r\x00y\x00l\x00 \x00A\x00n\x00t\x00o\x00n\x00i\x00o\x00\x0e\x00D\x00a\x00r\x00 ...", u'created_at': u'Mon Jun 02 12:11:30 +0000 2008', u'retweeted': False, u'in_reply_to_status_id': None, u'coordinates': None, u'id': 825129908, u'entities': r.expr({u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}), u'in_reply_to_status_id_str': None, u'in_reply_to_screen_name': None, u'id_str': u'825129908', u'place': None, u'retweet_count': 0, u'geo': None, u'in_reply_to_user_id_str': None, u'favorite_count': 0, u'in_reply_to_user_id': None}), u'lang': u'en', u'utc_offset': -21600, u'statuses_count': 23, u'description': u'Get a FREE DVD & brochures on buying a property in Paphos, Cyprus', u'friends_count': 309, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'profile_link_color': u'0084B4', u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png', u'notifications': False, u'geo_enabled': False, u'profile_background_color': u'C0DEED', u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'name': u'Dante', u'is_translation_enabled': False, u'profile_background_tile': False, u'favourites_count': 0, u'screen_name': u'prope3c7', u'url': u'http://t.co/mPAhFDHGFD', u'created_at': u'Mon May 19 16:47:46 +0000 2008', u'contributors_enabled': False, u'time_zone': u'Mountain Time (US & Canada)', u'profile_sidebar_border_color': u'C0DEED', u'default_profile': True, u'following': False, u'listed_count': 0}))

Activity

  1. neumino commented on Jul 15, 2014

    @neumino
    Member

    This field is causing the error:

    u'text': u"Cyprus finally won its' independence in 1960 under Archbishop Makarios. h\x00t\x00t\x00p\x00:\x00/\x00/\x00w\x00w\x00w\x00\x00\x00\x00\x00\x00\x00\x0e\x00D\x00a\x00r\x00r\x00y\x00l\x00 \x00A\x00n\x00t\x00o\x00n\x00i\x00o\x00\x0e\x00D\x00a\x00r\x00 ...",
    

    RethinkDB doesn't support the null char \x00 -- http://www.rethinkdb.com/docs/data-types/

    I guess we should provide a more friendly error?

    You can just remove the null char if you want to insert the document without the null character.
    str.replace('\x00', '') should do the trick I think;

  2. coffeemug commented on Jul 15, 2014

    @coffeemug
    Contributor

    I think that if at all possible, we should support null chars in the middle of strings. People often have data with null chars interspersed, and asking them to sanitize it results in a bad experience. I'm not sure how to deal with json spec conflicts, but if we could find a reasonable way of doing it, I think it would help a lot to be permissive about it.

    (Failing that, we should make the error message better, but I think it's not an ideal solution)

    Moving to 1.14-polish.

  3. added this to the milestone on Jul 15, 2014
  4. AtnNn commented on Jul 15, 2014

    @AtnNn
    Member

    JSON strings can contain any UTF-8 character, including null. However, null and other control characters need to be escaped. In python:

    >>> json.dumps("\x00")
    '"\\u0000"'
    >>> json.loads('"\\u0000"')
    u'\x00'
    >>> json.loads('"\x00"')
    ValueError: Invalid control character
  5. coffeemug commented on Jul 15, 2014

    @coffeemug
    Contributor

    Also, I believe the Python driver validated this and returned a good error message before on the client side. This seems like a regression, so we should add this case to the reql tests.

  6. danielmewes commented on Jul 15, 2014

    @danielmewes
    Member

    It is likely that cJSON is going to have issues with null characters, since it uses C strings in many places.

  7. srh commented on Jul 24, 2014

    @srh
    Contributor

    I believe some primary or sindex primary keys assume that strings can't have nul characters. Beware.

  8. modified the milestones: , on Aug 13, 2014
  9. mbican commented on Aug 15, 2014

    @mbican

    Null characters could be internally stored using modified utf8 http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8 bytes 0xC0,0x80 this way it would work in C based functions. Since null character is valid unicode character it's really inconvenient that rethinkdb prohibits them.

  10. mlucy commented on Aug 15, 2014

    @mlucy
    Member

    @mbican: I would be hesitant to change the strings people insert. It's confusing to insert a string with "\x00" and get back "\xc0\x80". I think we should just fix things so that people can have "\x00" in strings.

  11. modified the milestones: , on Sep 4, 2014
  12. danielmewes commented on Oct 9, 2014

    @danielmewes
    Member

    I split this into two issues:
    #3163 which is about supporting null characters in strings
    and #3164 to improve how driver's handle them until we do.

  13. modified the milestones: moved, on Oct 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions