expected conditions is a dict and each value is an object of ExpectedCondition instead of a list

Bug #1301026 reported by Charles Wang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MagnetoDB
Fix Released
Medium
Charles Wang

Bug Description

When parsing expected conditions, all items are placed into a dict with attribute as key and condition as value. Each value in the expected condition map is an object of ExpectedCondition instead of a list. The following code in cassandra_impl.py assumes it is a list.

    def _append_expected_conditions(self, expected_condition_map, schema,
                                    query_builder):
        init_length = len(query_builder)

        for attr_name, cond_list in expected_condition_map.iteritems():
            for condition in cond_list:
                self._append_expected_condition(
                    attr_name, condition, query_builder,
                    attr_name in schema.attribute_type_map
                )
                query_builder.append(" AND ")

        if len(query_builder) > init_length:
            query_builder.pop()

It should be changed to:

    def _append_expected_conditions(self, expected_condition_map, schema,
                                    query_builder):
        init_length = len(query_builder)

        for attr_name, condition in expected_condition_map.iteritems():
            self._append_expected_condition(
                attr_name, condition, query_builder,
                attr_name in schema.attribute_type_map
            )
            query_builder.append(" AND ")

        if len(query_builder) > init_length:
            query_builder.pop()

I have tried the fix with delta_item and update_item with conditions and the fix works. Without the fix, the conditional update and delete would fail.

Changed in magnetodb:
assignee: nobody → Charles Wang (charles-wang)
Revision history for this message
Dmitriy Ukhlov (dukhlov) wrote :

Hi Charles,
Yes I faced with this bug too. But I would prefer to fix this bug on the API side. Pleate take a look a look at magnetodb/api/amz/dynamodb/parser.py
and magnetodb/api/openstack/v1/parser.py
There is parse_expected_attribute_conditions methom which shold be rewritten to return map of list of Condition.

Please send your patch to Gerrit review when you are ready

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix proposed to magnetodb (master)

Fix proposed to branch: master
Review: https://review.openstack.org/90550

Changed in magnetodb:
status: New → In Progress
Changed in magnetodb:
milestone: none → 2.0.4
importance: Undecided → Medium
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix merged to magnetodb (master)

Reviewed: https://review.openstack.org/90550
Committed: https://git.openstack.org/cgit/stackforge/magnetodb/commit/?id=7c4f8bba5c1d3ee12236547e43d0717510c383e9
Submitter: Jenkins
Branch: master

commit 7c4f8bba5c1d3ee12236547e43d0717510c383e9
Author: Charles Wang <email address hidden>
Date: Sat Apr 26 12:49:31 2014 -0400

    Return list of ExpectedCondition in parsing

    Change parse_expected_attribute_conditions in dynamodb and v1 to
    return a list of ExpectedCondition which is expected in backend

    Change-Id: I816628daa1ef2bf3ca7a53bbeb6dd280b4babf60
    Closes-Bug: #1301026

Changed in magnetodb:
status: In Progress → Fix Committed
Changed in magnetodb:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.