Fix drivers_private_data update on deleted entries
The drivers_private_data is expected to be able to save new entries using the same keys as previously deleted entries. Before performing an update, it retrieves all entries related to the same entity to check if it needs to perform an update (including on deleted entries) or a new insertion. Unfortunately, the misinterpretation of a parameter in the manila DB API led to a bug that prevented deleted entries to be retrieved. This bugfix replaces the query ensuring that all entries (active and deleted) are retrieved so the update validation works. Closes-bug: #1721123 Change-Id: Id94544c9b8a534d7f0fe4e16bc57546002e33373
This commit is contained in:
parent
e741319d57
commit
ebac41d631
@ -3505,9 +3505,8 @@ def driver_private_data_update(context, entity_id, details,
|
||||
|
||||
with session.begin():
|
||||
# Process existing data
|
||||
# NOTE(u_glide): read_deleted=None means here 'read all'
|
||||
original_data = _driver_private_data_query(
|
||||
session, context, entity_id, read_deleted=None).all()
|
||||
original_data = session.query(models.DriverPrivateData).filter_by(
|
||||
entity_uuid=entity_id).all()
|
||||
|
||||
for data_ref in original_data:
|
||||
in_new_details = data_ref['key'] in new_details
|
||||
|
@ -1644,11 +1644,39 @@ class DriverPrivateDataDatabaseAPITestCase(test.TestCase):
|
||||
self.assertEqual({}, initial_data)
|
||||
self.assertEqual(valid, actual_data)
|
||||
|
||||
def test_update_with_duplicate(self):
|
||||
@ddt.data({'with_deleted': True, 'append': False},
|
||||
{'with_deleted': True, 'append': True},
|
||||
{'with_deleted': False, 'append': False},
|
||||
{'with_deleted': False, 'append': True})
|
||||
@ddt.unpack
|
||||
def test_update_with_more_values(self, with_deleted, append):
|
||||
test_id = self._get_driver_test_data()
|
||||
details = {"tee": "too"}
|
||||
more_details = {"foo": "bar"}
|
||||
result = {"tee": "too", "foo": "bar"}
|
||||
|
||||
db_api.driver_private_data_update(self.ctxt, test_id, details)
|
||||
if with_deleted:
|
||||
db_api.driver_private_data_delete(self.ctxt, test_id)
|
||||
if append:
|
||||
more_details.update(details)
|
||||
if with_deleted and not append:
|
||||
result.pop("tee")
|
||||
db_api.driver_private_data_update(self.ctxt, test_id, more_details)
|
||||
|
||||
actual_result = db_api.driver_private_data_get(self.ctxt,
|
||||
test_id)
|
||||
|
||||
self.assertEqual(result, actual_result)
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_update_with_duplicate(self, with_deleted):
|
||||
test_id = self._get_driver_test_data()
|
||||
details = {"tee": "too"}
|
||||
|
||||
db_api.driver_private_data_update(self.ctxt, test_id, details)
|
||||
if with_deleted:
|
||||
db_api.driver_private_data_delete(self.ctxt, test_id)
|
||||
db_api.driver_private_data_update(self.ctxt, test_id, details)
|
||||
|
||||
actual_result = db_api.driver_private_data_get(self.ctxt,
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed the database update query for the
|
||||
drivers' private data store that was failing
|
||||
to update any rows marked as deleted.
|
||||
|
Loading…
Reference in New Issue
Block a user