Ticket #47 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Entity.set to/from_dict

Reported by: guest Owned by:
Priority: normal Milestone: 0.6
Component: core Version:
Keywords: Entity set from_dict Cc: jaraco@…

Description

Reposted from discussion http://groups.google.com/group/sqlelixir/browse_thread/thread/947e4eac58490718 .

Beginning with 0.6, Entity.set does something different. It attempts to reassemble an object from a JSON-generated structure:

def set(self, **kwargs):

self.from_dict(kwargs)

Unfortunately, the from_dict method fails to set properties who's property name does not match the column name:

class Attribute(Entity):

key = Field(String(256), colname='attribute_key')

new_attr = Attribute() new_attr.set(key='foo') # fails to set key beginning in 0.6.

Perhaps to_dict and from_dict could be kept independent of .set, maintaining backward compatibility.

Furthermore, I'm unsure the motivation for using column names instead of entity properties, but I would suggest even using entity properties for generating the JSON dicts. I'm not sure if this is feasible, but from my perspective, one of the primary advantages of Elixir/SQLAlchemy is that it abstracts underlying details such as the column names so that more appropriate and consistent names can be used in the application. The to/from_dict methods violate this abstraction, and I believe that is why my app fails.

Is there perhaps a better way to implement the to/from_dict methods to (a) better handle properties whose names differ from the column names and (b) allow set to be backward compatible with 0.5?

Attachments

test_set.patch (2.0 kB) - added by guest 5 years ago.
A testcase as a patch to r339 to demonstrate failing behavior.

Change History

Changed 5 years ago by guest

A testcase as a patch to r339 to demonstrate failing behavior.

Changed 5 years ago by ged

  • status changed from new to closed
  • resolution set to fixed

fixed in r360

Note: See TracTickets for help on using tickets.