From 7c92317641961f7cec441f3692808eb005f99561 Mon Sep 17 00:00:00 2001 From: yordy aquiles pena espinosa Date: Wed, 5 Nov 2025 21:55:04 -0400 Subject: [PATCH 1/2] fix(models): correct Row.fromMap constructor to handle columns named 'data' - Changed data assignment from 'map[\"data\"] ?? map' to 'map' in Row.fromMap constructor - This fixes the TypeError that occurred when a table had a column named 'data' - Added comprehensive tests to verify the fix and prevent regressions - Fixes #281" --- lib/src/models/row.dart | 2 +- test/src/models/row_test.dart | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/src/models/row.dart b/lib/src/models/row.dart index 28a88963..82dd1e94 100644 --- a/lib/src/models/row.dart +++ b/lib/src/models/row.dart @@ -45,7 +45,7 @@ class Row implements Model { $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), $permissions: List.from(map['\$permissions'] ?? []), - data: map["data"] ?? map, + data: map, ); } diff --git a/test/src/models/row_test.dart b/test/src/models/row_test.dart index fed01ffa..fdf8883d 100644 --- a/test/src/models/row_test.dart +++ b/test/src/models/row_test.dart @@ -26,5 +26,60 @@ void main() { expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.$permissions, []); }); + + // Test for the specific bug reported in issue #281 + test('fromMap should handle columns named data without type errors', () { + final map = { + '\$id': 'row123', + '\$sequence': 1, + '\$tableId': 'table1', + '\$databaseId': 'db1', + '\$createdAt': '2023-01-01T00:00:00.000Z', + '\$updatedAt': '2023-01-01T00:00:00.000Z', + '\$permissions': ['read', 'write'], + 'data': + 'this is a string value in data column', // This column name was causing the issue + 'name': 'Test Row', + 'value': 42, + }; + + // This should not throw a TypeError anymore + final row = Row.fromMap(map); + + // Verify that data contains the complete map + expect(row.data, isA>()); + expect(row.data['data'], equals('this is a string value in data column')); + expect(row.data['name'], equals('Test Row')); + expect(row.data['value'], equals(42)); + expect(row.data['\$id'], equals('row123')); + + // Verify that the main fields are assigned correctly + expect(row.$id, equals('row123')); + expect(row.$sequence, equals(1)); + }); + + // Additional test to verify behavior when there's no data column + test('fromMap should work correctly when map does not contain data column', + () { + final map = { + '\$id': 'row456', + '\$sequence': 2, + '\$tableId': 'table1', + '\$databaseId': 'db1', + '\$createdAt': '2023-01-01T00:00:00.000Z', + '\$updatedAt': '2023-01-01T00:00:00.000Z', + '\$permissions': ['read'], + 'name': 'Another Row', + 'value': 100, + // No data column - this should work fine + }; + + final row = Row.fromMap(map); + + expect(row.data, isA>()); + expect(row.data['name'], equals('Another Row')); + expect(row.data['value'], equals(100)); + expect(row.$id, equals('row456')); + }); }); } From 032c96e42b7a3902ebf82ee917faa1671b6ab17b Mon Sep 17 00:00:00 2001 From: yordy aquiles pena espinosa Date: Wed, 5 Nov 2025 22:00:48 -0400 Subject: [PATCH 2/2] fix(models): correct Row.fromMap constructor to handle columns named data - Changed data assignment to use complete map instead of data field - This fixes TypeError when table has column named data - Added tests to verify the fix - Fixes #281 --- lib/src/models/row.dart | 1 + test/src/models/row_test.dart | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/models/row.dart b/lib/src/models/row.dart index 82dd1e94..f64ece60 100644 --- a/lib/src/models/row.dart +++ b/lib/src/models/row.dart @@ -45,6 +45,7 @@ class Row implements Model { $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), $permissions: List.from(map['\$permissions'] ?? []), + // Assign the entire map to data data: map, ); } diff --git a/test/src/models/row_test.dart b/test/src/models/row_test.dart index fdf8883d..325abbf9 100644 --- a/test/src/models/row_test.dart +++ b/test/src/models/row_test.dart @@ -27,7 +27,8 @@ void main() { expect(result.$permissions, []); }); - // Test for the specific bug reported in issue #281 + // Test for the specific bug + //reported in issue #281 test('fromMap should handle columns named data without type errors', () { final map = { '\$id': 'row123',