Commits

Matthew Schinckel  committed c4b3b00

Fix for when simplejson decides to use unicode rather than strings for dictionary keys.

  • Participants
  • Parent commits 49aaf07

Comments (0)

Files changed (1)

File rest_api/options.py

                 # Not sure how m2m will go here.
                 if incoming.get(f.get_accessor_name(), False):
                     related[f.get_accessor_name()] = incoming.pop(f.get_accessor_name())
-            instance = self.model(**incoming)
+            instance = self.model(**dict([(str(k),v) for (k,v) in incoming.iteritems()]))
             try:
                 # If there are audit fields, then update the values.
                 instance.created_by = request.user
                                     x[k] = field.rel.to.objects.get(pk=v)
                             getattr(instance, accessor).create(**x)
                 created.append(instance.pk)
-            except IntegrityError:
-                raise http.Conflict
+            except IntegrityError, arg:
+                raise http.Conflict(arg.args[0])
         objects = self.model.objects.filter(pk__in=created)
         for obj in objects:
             self.log_addition(request, obj)
                                 continue
                             if f.rel:
                                 val[k] = f.rel.to.objects.get(pk=v)
-                        getattr(instance, key).create(**val)
+                        getattr(instance, key).create(**dict([(str(_k), _v) for _k, _v in val.items()]))
                 elif getattr(instance, key) != value:
                     try:
                         setattr(instance, key, value)
         instance.updated_by = request.user
         try:
             instance.save()
-        except IntegrityError:
-            raise http.Conflict
+        except IntegrityError, arg:
+            raise http.Conflict(arg.args[0])
 
         if len(changed):
             message = "Changed %s." % ", ".join(["%s to %s" % x for x in changed.iteritems()])