Skip to content
This repository
Browse code

Over trim the string to handle wide characters

  • Loading branch information...
commit fc79e5cc636f93257f807eb1426cdadc57dc6c37 1 parent 0ab82f0
Edmund von der Burg authored March 23, 2012

Showing 1 changed file with 15 additions and 1 deletion. Show diff stats Hide diff stats

  1. 16  pylib/pyc/utils/check_petition_feeds.py
16  pylib/pyc/utils/check_petition_feeds.py
@@ -42,7 +42,21 @@
42 42
                 'council'     : council,
43 43
                 'title'       : rss_entry['title'][:200],
44 44
                 'url'         : rss_entry['link'],
45  
-                'description' : rss_entry['summary'][:2000],
  45
+                'description' : rss_entry['summary'][:1900],  # see note below
46 46
                 'pub_date'    : pub_date,
47 47
             },
48 48
         )
  49
+
  50
+        # Note on the 1900 cap.
  51
+        #
  52
+        # The database field can store 2000 chars, but the encoding is SQL so it is
  53
+        # actually 2000 bytes. Hence any entry containing wide characters that gets
  54
+        # truncated may be 2000 chars, but > 2000 bytes causing the insert query to
  55
+        # fail.
  56
+        #
  57
+        #   django.db.utils.DatabaseError: value too long for type character varying(2000)
  58
+        #
  59
+        # Rather than mess around with the schema to increse the limit (South not 
  60
+        # used in this project), or trim the string to be < 2000 bytes we just trim it
  61
+        # to 1900 chars and hope that will do the trick.
  62
+                

0 notes on commit fc79e5c

Please sign in to comment.
Something went wrong with that request. Please try again.