You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When upserting a Project, the following exception is thrown:
type 'Project' is not a subtype of type 'Customer' of 'input' #0 CustomerAdapter.toSupabase (package:tragwerk_app/brick/adapters/customer_adapter.g.dart:344:52)
#1 SupabaseProvider._upsertByType (package:brick_supabase/src/supabase_provider.dart:107:34)
#2 SupabaseProvider._recursiveAssociationUpsert (package:brick_supabase/src/supabase_provider.dart:149:18)
#3 SupabaseProvider._recursiveAssociationUpsert (package:brick_supabase/src/supabase_provider.dart:142:13)
#4 SupabaseProvider.upsert (package:brick_supabase/src/supabase_provider.dart:90:18)
#5 OfflineFirstRepository.upsert (package:brick_offline_first/src/offline_first_repository.dart:404:28)
<asynchronous suspension>
I checked the debugger and the issue is inside the _recursiveAssociationUpsert method.
When it is first called from the upsert method, the instance is the project data and the type is Project, which is correct. But when the associations are iterated over in the for loop, the _recursiveAssociationUpsert is called again, but this time with the type of Customer which is also correct, but the instance is the project data instead of the nested customer data. This means that the _upsertByType method is called with the project data but the Customer type. For that reason, the exception is thrown inside the toSupabase method, as the project data is passed instead of the customer data.
I guess the fix should be to pass the associated field of the model instead of the original model here:
Great investigation work. Unfortunately, dynamic properties can't be invoked in strong Dart land, so I think the best way to handle this is to convert everything to a map first and then process it. I've made some changes and published the fixes for brick_supabase_generators and brick_supabase in #430
In my project, I have a model Project and a model Customer:
When upserting a Project, the following exception is thrown:
I checked the debugger and the issue is inside the
_recursiveAssociationUpsert
method.When it is first called from the
upsert
method, the instance is the project data and the type isProject
, which is correct. But when the associations are iterated over in the for loop, the_recursiveAssociationUpsert
is called again, but this time with the type ofCustomer
which is also correct, but the instance is the project data instead of the nested customer data. This means that the_upsertByType
method is called with the project data but theCustomer
type. For that reason, the exception is thrown inside thetoSupabase
method, as the project data is passed instead of the customer data.I guess the fix should be to pass the associated field of the model instead of the original model here:
brick/packages/brick_supabase/lib/src/supabase_provider.dart
Line 143 in fe6c1d7
The text was updated successfully, but these errors were encountered: