@@ -154,3 +154,139 @@ class Meta:
154154 BAModel .create_table (read_capacity_units = 1 , write_capacity_units = 1 )
155155 BAModel ('pkey' , flag = True ).save ()
156156 assert (0 , 0 ) == migrate_boolean_attributes (BAModel , ['flag' ], allow_rate_limited_scan_without_consumed_capacity = True )
157+
158+
159+ @pytest .mark .parametrize ("flag_value" ,[True , False , None ])
160+ @pytest .mark .ddblocal
161+ def test_legacy_boolean_attribute_deserialization_in_update (ddb_url , flag_value ):
162+ class BAModel (Model ):
163+ class Meta :
164+ table_name = 'lba_deserialization_test'
165+ host = ddb_url
166+ id = UnicodeAttribute (hash_key = True )
167+ flag = BooleanAttribute (null = True )
168+ value = UnicodeAttribute (null = True )
169+
170+ class LBAModel (Model ):
171+ class Meta :
172+ table_name = 'lba_deserialization_test'
173+ host = ddb_url
174+ id = UnicodeAttribute (hash_key = True )
175+ flag = LegacyBooleanAttribute (null = True )
176+ value = UnicodeAttribute (null = True )
177+
178+ BAModel .create_table (read_capacity_units = 1 , write_capacity_units = 1 )
179+
180+ # Create objects with a BooleanAttribute flag
181+ BAModel ('pkey' , flag = flag_value , value = 'value' ).save ()
182+
183+ # Check we are able to read the flag with LegacyBooleanAttribute
184+ assert flag_value == LBAModel .get ('pkey' ).flag
185+
186+ # Update a value in the model causing LegacyBooleanAttribute to be deserialized
187+ LBAModel .get ('pkey' ).update (actions = [LBAModel .value .set ('new value' )])
188+
189+ # Check we are able to read the flag with LegacyBooleanAttribute
190+ assert flag_value == LBAModel .get ('pkey' ).flag
191+
192+
193+ @pytest .mark .parametrize ("flag_value" ,[True , False , None ])
194+ @pytest .mark .ddblocal
195+ def test_legacy_boolean_attribute_deserialization_in_update_item (ddb_url , flag_value ):
196+ class BAModel (Model ):
197+ class Meta :
198+ table_name = 'lba_deserialization_test'
199+ host = ddb_url
200+ id = UnicodeAttribute (hash_key = True )
201+ flag = BooleanAttribute (null = True )
202+ value = UnicodeAttribute (null = True )
203+
204+ class LBAModel (Model ):
205+ class Meta :
206+ table_name = 'lba_deserialization_test'
207+ host = ddb_url
208+ id = UnicodeAttribute (hash_key = True )
209+ flag = LegacyBooleanAttribute (null = True )
210+ value = UnicodeAttribute (null = True )
211+
212+ BAModel .create_table (read_capacity_units = 1 , write_capacity_units = 1 )
213+
214+ # Create objects with a BooleanAttribute flag
215+ BAModel ('pkey' , flag = flag_value , value = 'value' ).save ()
216+
217+ # Check we are able to read the flag with LegacyBooleanAttribute
218+ assert flag_value == LBAModel .get ('pkey' ).flag
219+
220+ # Update a value in the model causing LegacyBooleanAttribute to be deserialized
221+ LBAModel .get ('pkey' ).update_item ('value' , 'new value' , 'PUT' )
222+
223+ # Check we are able to read the flag with LegacyBooleanAttribute
224+ assert flag_value == LBAModel .get ('pkey' ).flag
225+
226+
227+ @pytest .mark .parametrize ("flag_value" ,[True , False , None ])
228+ @pytest .mark .ddblocal
229+ def test_boolean_attribute_deserialization_in_update (ddb_url , flag_value ):
230+ class BAModel (Model ):
231+ class Meta :
232+ table_name = 'ba_deserialization_test'
233+ host = ddb_url
234+ id = UnicodeAttribute (hash_key = True )
235+ flag = BooleanAttribute (null = True )
236+ value = UnicodeAttribute (null = True )
237+
238+ class LBAModel (Model ):
239+ class Meta :
240+ table_name = 'ba_deserialization_test'
241+ host = ddb_url
242+ id = UnicodeAttribute (hash_key = True )
243+ flag = LegacyBooleanAttribute (null = True )
244+ value = UnicodeAttribute (null = True )
245+
246+ LBAModel .create_table (read_capacity_units = 1 , write_capacity_units = 1 )
247+
248+ # Create an object with a LegacyBooleanAttribute flag
249+ LBAModel ('pkey' , flag = flag_value , value = 'value' ).save ()
250+
251+ # Check we are able to read the flag with BooleanAttribute
252+ assert flag_value == BAModel .get ('pkey' ).flag
253+
254+ # Update a value in the model causing BooleanAttribute to be deserialized
255+ BAModel .get ('pkey' ).update (actions = [BAModel .value .set ('new value' )])
256+
257+ # Check we are able to read the flag with BooleanAttribute
258+ assert flag_value == BAModel .get ('pkey' ).flag
259+
260+
261+ @pytest .mark .parametrize ("flag_value" ,[True , False , None ])
262+ @pytest .mark .ddblocal
263+ def test_boolean_attribute_deserialization_in_update_item (ddb_url , flag_value ):
264+ class BAModel (Model ):
265+ class Meta :
266+ table_name = 'ba_deserialization_test'
267+ host = ddb_url
268+ id = UnicodeAttribute (hash_key = True )
269+ flag = BooleanAttribute (null = True )
270+ value = UnicodeAttribute (null = True )
271+
272+ class LBAModel (Model ):
273+ class Meta :
274+ table_name = 'ba_deserialization_test'
275+ host = ddb_url
276+ id = UnicodeAttribute (hash_key = True )
277+ flag = LegacyBooleanAttribute (null = True )
278+ value = UnicodeAttribute (null = True )
279+
280+ LBAModel .create_table (read_capacity_units = 1 , write_capacity_units = 1 )
281+
282+ # Create an object with a LegacyBooleanAttribute flag
283+ LBAModel ('pkey' , flag = flag_value , value = 'value' ).save ()
284+
285+ # Check we are able to read the flag with BooleanAttribute
286+ assert flag_value == BAModel .get ('pkey' ).flag
287+
288+ # Update a value in the model causing BooleanAttribute to be deserialized
289+ BAModel .get ('pkey' ).update_item ('value' , 'new value' , 'PUT' )
290+
291+ # Check we are able to read the flag with BooleanAttribute
292+ assert flag_value == BAModel .get ('pkey' ).flag
0 commit comments