Opened 8 years ago

Closed 8 years ago

#25829 closed Uncategorized (invalid)

Cannot store a dict object into HStoreField

Reported by: Wael BEN ZID EL GUEBSI Owned by:
Component: contrib.postgres Version: 1.8
Severity: Normal Keywords: HStoreField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Wael BEN ZID EL GUEBSI)

I want to store a tweet status in database, below the model definition

class Status(models.Model):
    raw = pgfields.HStoreField()
    # other fields

status = Status(raw=dict_object)

and I got this error:

ProgrammingError: ARRAY types integer and integer[] cannot be matched
LINE 1: ... 'id_str', 'screen_name', 'name'], ARRAY[9284062, ARRAY[3, 1...

below the data that I want to insert:

{u'contributors': None,
 u'coordinates': None,
 u'created_at': u'Sat Nov 28 19:36:10 +0000 2015',
 u'entities': {u'hashtags': [{u'indices': [67, 78], u'text': u'devfestlon'}],
               u'media': [{u'display_url': u'pic.twitter.com/jsQ5eqTYvD',
                           u'expanded_url': u'http://twitter.com/gerardsans/status/670682424477679617/photo/1',
                           u'id': 670682412188307462,
                           u'id_str': u'670682412188307462',
                           u'indices': [114, 137],
                           u'media_url': u'http://pbs.twimg.com/media/CU6-GbeWEAYk-2U.jpg',
                           u'media_url_https': u'https://pbs.twimg.com/media/CU6-GbeWEAYk-2U.jpg',
                           u'sizes': {u'large': {u'h': 756,
                                                 u'resize': u'fit',
                                                 u'w': 1021},
                                      u'medium': {u'h': 444,
                                                  u'resize': u'fit',
                                                  u'w': 600},
                                      u'small': {u'h': 251,
                                                 u'resize': u'fit',
                                                 u'w': 340},
                                      u'thumb': {u'h': 150,
                                                 u'resize': u'crop',
                                                 u'w': 150}},
                           u'source_status_id': 670682424477679617,
                           u'source_status_id_str': u'670682424477679617',
                           u'source_user_id': 9284062,
                           u'source_user_id_str': u'9284062',
                           u'type': u'photo',
                           u'url': u'https://t.co/jsQ5eqTYvD'}],
               u'symbols': [],
               u'urls': [{u'display_url': u'slides.com/gerardsans/str\u2026',
                          u'expanded_url': u'http://slides.com/gerardsans/streams-in-angular2',
                          u'indices': [90, 113],
                          u'url': u'https://t.co/NhKrNLo0og'}],
               u'user_mentions': [{u'id': 9284062,
                                   u'id_str': u'9284062',
                                   u'indices': [3, 14],
                                   u'name': u'gerardsans',
                                   u'screen_name': u'gerardsans'},
                                  {u'id': 53442117,
                                   u'id_str': u'53442117',
                                   u'indices': [79, 89],
                                   u'name': u'GDG London',
                                   u'screen_name': u'gdglondon'}]},
 u'favorite_count': 0,
 u'favorited': False,
 u'geo': None,
 u'id': 670687648726519809,
 u'id_str': u'670687648726519809',
 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'is_quote_status': False,
 u'lang': u'en',
 u'metadata': {u'iso_language_code': u'en', u'result_type': u'recent'},
 u'place': None,
 u'possibly_sensitive': False,
 u'retweet_count': 2,
 u'retweeted': False,
 u'retweeted_status': {u'contributors': None,
                       u'coordinates': None,
                       u'created_at': u'Sat Nov 28 19:15:25 +0000 2015',
                       u'entities': {u'hashtags': [{u'indices': [51, 62],
                                                    u'text': u'devfestlon'}],
                                     u'media': [{u'display_url': u'pic.twitter.com/jsQ5eqTYvD',
                                                 u'expanded_url': u'http://twitter.com/gerardsans/status/670682424477679617/photo/1',
                                                 u'id': 670682412188307462,
                                                 u'id_str': u'670682412188307462',
                                                 u'indices': [98, 121],
                                                 u'media_url': u'http://pbs.twimg.com/media/CU6-GbeWEAYk-2U.jpg',
                                                 u'media_url_https': u'https://pbs.twimg.com/media/CU6-GbeWEAYk-2U.jpg',
                                                 u'sizes': {u'large': {u'h': 756,
                                                                       u'resize': u'fit',
                                                                       u'w': 1021},
                                                            u'medium': {u'h': 444,
                                                                        u'resize': u'fit',
                                                                        u'w': 600},
                                                            u'small': {u'h': 251,
                                                                       u'resize': u'fit',
                                                                       u'w': 340},
                                                            u'thumb': {u'h': 150,
                                                                       u'resize': u'crop',
                                                                       u'w': 150}},
                                                 u'type': u'photo',
                                                 u'url': u'https://t.co/jsQ5eqTYvD'}],
                                     u'symbols': [],
                                     u'urls': [{u'display_url': u'slides.com/gerardsans/str\u2026',
                                                u'expanded_url': u'http://slides.com/gerardsans/streams-in-angular2',
                                                u'indices': [74, 97],
                                                u'url': u'https://t.co/NhKrNLo0og'}],
                                     u'user_mentions': [{u'id': 53442117,
                                                         u'id_str': u'53442117',
                                                         u'indices': [63,
                                                                      73],
                                                         u'name': u'GDG London',
                                                         u'screen_name': u'gdglondon'}]},
                       u'favorite_count': 2,
                       u'favorited': False,
                       u'geo': None,
                       u'id': 670682424477679617,
                       u'id_str': u'670682424477679617',
                       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'is_quote_status': False,
                       u'lang': u'en',
                       u'metadata': {u'iso_language_code': u'en',
                                     u'result_type': u'recent'},
                       u'place': None,
                       u'possibly_sensitive': False,
                       u'retweet_count': 2,
                       u'retweeted': False,
                       u'source': u'<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>',
                       u'text': u'Slides from Asynchronous Data Streams in Angular 2 #devfestlon @gdglondon https://t.co/NhKrNLo0og https://t.co/jsQ5eqTYvD',
                       u'truncated': False,
                       u'user': {u'contributors_enabled': False,
                                 u'created_at': u'Sat Oct 06 20:04:48 +0000 2007',
                                 u'default_profile': True,
                                 u'default_profile_image': False,
                                 u'description': u'AngularJS GDE | Coding is fun | Coded something awesome today? | #AngularJS & #JavaScript are the new kings! \u2764 | @angularjs_labs Meetup organiser',
                                 u'entities': {u'description': {u'urls': []},
                                               u'url': {u'urls': [{u'display_url': u'medium.com/@gerard.sans',
                                                                   u'expanded_url': u'https://medium.com/@gerard.sans',
                                                                   u'indices': [0,
                                                                                23],
                                                                   u'url': u'https://t.co/OzlOVVZNqK'}]}},
                                 u'favourites_count': 1237,
                                 u'follow_request_sent': False,
                                 u'followers_count': 768,
                                 u'following': False,
                                 u'friends_count': 785,
                                 u'geo_enabled': True,
                                 u'has_extended_profile': False,
                                 u'id': 9284062,
                                 u'id_str': u'9284062',
                                 u'is_translation_enabled': False,
                                 u'is_translator': False,
                                 u'lang': u'en',
                                 u'listed_count': 102,
                                 u'location': u'London \u2602',
                                 u'name': u'gerardsans',
                                 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_banner_url': u'https://pbs.twimg.com/profile_banners/9284062/1448587325',
                                 u'profile_image_url': u'http://pbs.twimg.com/profile_images/585578015641448448/pn0ZzQuj_normal.png',
                                 u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/585578015641448448/pn0ZzQuj_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'gerardsans',
                                 u'statuses_count': 1470,
                                 u'time_zone': u'Greenland',
                                 u'url': u'https://t.co/OzlOVVZNqK',
                                 u'utc_offset': -10800,
                                 u'verified': False}},
 u'source': u'<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>',
 u'text': u'RT @gerardsans: Slides from Asynchronous Data Streams in Angular 2 #devfestlon @gdglondon https://t.co/NhKrNLo0og https://t.co/jsQ5eqTYvD',
 u'truncated': False,
 u'user': {u'contributors_enabled': False,
           u'created_at': u'Thu Jun 18 08:40:05 +0000 2009',
           u'default_profile': False,
           u'default_profile_image': False,
           u'description': u'Web Specialist - Java and JavaScript technologies - @ZenikaLille',
           u'entities': {u'description': {u'urls': []},
                         u'url': {u'urls': [{u'display_url': u'Gillespie59.github.io',
                                             u'expanded_url': u'http://Gillespie59.github.io',
                                             u'indices': [0, 23],
                                             u'url': u'https://t.co/lWeVaL99hb'}]}},
           u'favourites_count': 1596,
           u'follow_request_sent': False,
           u'followers_count': 865,
           u'following': False,
           u'friends_count': 1448,
           u'geo_enabled': True,
           u'has_extended_profile': True,
           u'id': 48291605,
           u'id_str': u'48291605',
           u'is_translation_enabled': False,
           u'is_translator': False,
           u'lang': u'fr',
           u'listed_count': 131,
           u'location': u'Lille - France',
           u'name': u'Emmanuel DEMEY',
           u'notifications': False,
           u'profile_background_color': u'022330',
           u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme15/bg.png',
           u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme15/bg.png',
           u'profile_background_tile': False,
           u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/48291605/1427485955',
           u'profile_image_url': u'http://pbs.twimg.com/profile_images/628190699951923200/vS3yoC1K_normal.jpg',
           u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/628190699951923200/vS3yoC1K_normal.jpg',
           u'profile_link_color': u'0084B4',
           u'profile_sidebar_border_color': u'A8C7F7',
           u'profile_sidebar_fill_color': u'C0DFEC',
           u'profile_text_color': u'333333',
           u'profile_use_background_image': True,
           u'protected': False,
           u'screen_name': u'EmmanuelDemey',
           u'statuses_count': 4723,
           u'time_zone': u'Paris',
           u'url': u'https://t.co/lWeVaL99hb',
           u'utc_offset': 3600,
           u'verified': False}}

Change History (2)

comment:1 by Wael BEN ZID EL GUEBSI, 8 years ago

Description: modified (diff)

comment:2 by Carl Meyer, 8 years ago

Resolution: invalid
Status: newclosed

HStoreField (and the Postgres hstore type in general) can't store arbitrarily nested mappings of arbitrary types, only single level mappings of string to string (as noted in the first sentence of the HStoreField docs). You may want a JSONField instead.

Note: See TracTickets for help on using tickets.
Back to Top