← Back to team overview

maas-devel team mailing list archive

Re: ProgrammingError: can't adapt type 'dict'

 

>From looking at the bottom of the stack, you are passing the dict
{'power_address': '10.0.0.108', ...} in for the SQL snippet:
 "power_parameters" = %s

I'm guessing you need to actually have the dict serialized into some form
that is acceptable as SQL. I'm not sure what the type of "power_parameters"
actually is, though I would guess it is some sort of string/blob.

I don't quite see why setting distro_series is affecting this, but it
sounds like power_parameters are being read and deserialized but not
serialized again when trying to write them back to the DB.

John
=:->


On Tue, May 6, 2014 at 8:12 AM, Julian Edwards <julian.edwards@xxxxxxxxxxxxx
> wrote:

> Anyone got the faintest idea what's going on here?  There's no error in
> the postgres log (I enabled statement logging).
>
> ----
>
> In [6]: n.set_distro_series('')
> ---------------------------------------------------------------------------
> ProgrammingError                          Traceback (most recent call last)
> <ipython-input-6-7920419dca0f> in <module>()
> ----> 1 n.set_distro_series('')
>
> /usr/lib/python2.7/dist-packages/maasserver/models/node.pyc in
> set_distro_series(self, series)
>
>     748         """Set the distro series to install that node."""
>     749         self.distro_series = series
> --> 750         self.save()
>     751
>     752     def get_effective_power_parameters(self):
>
> /usr/lib/python2.7/dist-packages/maasserver/models/cleansave.pyc in
> save(self, *args, **kwargs)
>
>      36     def save(self, *args, **kwargs):
>      37         self.full_clean()
> ---> 38         return super(CleanSave, self).save(*args, **kwargs)
>
> /usr/lib/python2.7/dist-packages/maasserver/models/timestampedmodel.pyc
> in save(self, *args, **kwargs)
>
>      53             self.created = current_time
>      54         self.updated = current_time
> ---> 55         return super(TimestampedModel, self).save(*args, **kwargs)
>
> /usr/lib/python2.7/dist-packages/django/db/models/base.pyc in save(self,
> force_insert, force_update, using, update_fields)
>
>     543
>     544         self.save_base(using=using, force_insert=force_insert,
> --> 545                        force_update=force_update,
> update_fields=update_fields)
>
>     546     save.alters_data = True
>     547
>
> /usr/lib/python2.7/dist-packages/django/db/models/base.pyc in
> save_base(self, raw, force_insert, force_update, using, update_fields)
>
>     571             if not raw:
>     572                 self._save_parents(cls, using, update_fields)
> --> 573             updated = self._save_table(raw, cls, force_insert,
> force_update, using, update_fields)
>     574         # Store the database on which the object was saved
>     575         self._state.db = using
>
> /usr/lib/python2.7/dist-packages/django/db/models/base.pyc in
> _save_table(self, raw, cls, force_insert, force_update, using,
> update_fields)
>     633             forced_update = update_fields or force_update
>     634             updated = self._do_update(base_qs, using, pk_val,
> values, update_fields,
> --> 635                                       forced_update)
>     636             if force_update and not updated:
>     637                 raise DatabaseError("Forced update did not
> affect any rows.")
>
>
> /usr/lib/python2.7/dist-packages/django/db/models/base.pyc in
> _do_update(self, base_qs, using, pk_val, values, update_fields,
> forced_update)
>     677             else:
>     678                 return False
> --> 679         return filtered._update(values) > 0
>     680
>     681     def _do_insert(self, manager, using, fields, update_pk, raw):
>
> /usr/lib/python2.7/dist-packages/django/db/models/query.pyc in
> _update(self, values)
>
>     505         query.add_update_fields(values)
>     506         self._result_cache = None
> --> 507         return query.get_compiler(self.db).execute_sql(None)
>     508     _update.alters_data = True
>     509
>
> /usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.pyc in
> execute_sql(self, result_type)
>     973         related queries are not available.
>     974         """
> --> 975         cursor = super(SQLUpdateCompiler,
> self).execute_sql(result_type)
>     976         rows = cursor.rowcount if cursor else 0
>     977         is_empty = cursor is None
>
> /usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.pyc in
> execute_sql(self, result_type)
>     779
>     780         cursor = self.connection.cursor()
> --> 781         cursor.execute(sql, params)
>     782
>     783         if not result_type:
>
> /usr/lib/python2.7/dist-packages/django/db/backends/util.pyc in
> execute(self, sql, params)
>      51                 return self.cursor.execute(sql)
>      52             else:
> ---> 53                 return self.cursor.execute(sql, params)
>      54
>      55     def executemany(self, sql, param_list):
>
> /usr/lib/python2.7/dist-packages/django/db/utils.pyc in __exit__(self,
> exc_type, exc_value, traceback)
>      97                 if dj_exc_type not in (DataError, IntegrityError):
>      98                     self.wrapper.errors_occurred = True
> ---> 99                 six.reraise(dj_exc_type, dj_exc_value, traceback)
>     100
>     101     def __call__(self, func):
>
> /usr/lib/python2.7/dist-packages/django/db/backends/util.pyc in
> execute(self, sql, params)
>      51                 return self.cursor.execute(sql)
>      52             else:
> ---> 53                 return self.cursor.execute(sql, params)
>      54
>      55     def executemany(self, sql, param_list):
>
> ProgrammingError: can't adapt type 'dict'
>
> In [7]: pdb.pm()
> > /usr/lib/python2.7/dist-packages/django/db/backends/util.py(53)execute()
> -> return self.cursor.execute(sql, params)
> (Pdb) sql
> u'UPDATE "maasserver_node" SET "created" = %s, "updated" = %s,
> "system_id" = %s, "hostname" = %s, "status" = %s, "owner_id" = NULL,
> "distro_series" = %s, "architecture" = %s, "routers" = %s, "agent_name"
> = %s, "zone_id" = %s, "cpu_count" = %s, "memory" = %s, "storage" = %s,
> "power_type" = %s, "power_parameters" = %s, "token_id" = NULL, "error" =
> %s, "netboot" = %s, "nodegroup_id" = %s WHERE "maasserver_node"."id" = %s '
> (Pdb) params
> (u'2014-04-30 19:14:00.754561', u'2014-05-06 14:06:59.220649',
> u'node-c46c458c-d047-11e3-af93-e4115b13819f', u'nuc1', 4, '',
> u'amd64/hwe-s', {}, u'', 1, 4, 4096, 1408, u'amt', '{"power_address":
> "10.0.0.108", "power_pass": "Password1+", "mac_address":
> "EC:A8:6B:FE:13:B6"}', u'finished [6/6]', True, 1, 13)
>
> --
> Mailing list: https://launchpad.net/~maas-devel
> Post to     : maas-devel@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~maas-devel
> More help   : https://help.launchpad.net/ListHelp
>

Follow ups

References