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
{{ message }}
Repository navigation
type 'Null' is not a subtype of type 'List<dynamic>' in type cast #536
I have a table called city that has id, a1, and a2 columns, I want to do a union all query and get the sum of the particularly same rows, this is my endpoint:
Future<List<List<dynamic>>> fetchMatchedCity(Session session) async {
session.log("querying match...");
final start = DateTime.now().millisecond;
final result = await session.db.query(""" select id1, id2, sum(score) from (
select t1.id as id1 , t2.id as id2, 1 as score from city as t1, city as t2 where t1.a1 = t2.a1 and t1.id <> t2.id union all
select t1.id as id1 , t2.id as id2, 1 as score from city as t1, city as t2 where t1.a2 = t2.a2 and t1.id <> t2.id
) as final
where id1 > id2
group by (id1, id2) order by sum(score) desc """);
return result;
}
I removed the usage of the result of await client.city.fetchMatchedCity(); due to reduce the risk of errors! but I still get following error:
flutter: FormatException: No deserialization found for type dynamic
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: No deserialization found for type dynamic
#0 SerializationManager.deserialize (package:serverpod_serialization/src/serialization.dart:73:5)
#1 Protocol.deserialize (package:hlafit_client/src/protocol/protocol.dart:107:18)
#2 Protocol.deserialize.<anonymous closure> (package:hlafit_client/src/protocol/protocol.dart:96:40)
#3 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#4 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#5 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#6 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#7 new List.of (dart:core-patch/array_patch.dart:51:28)
P.S: Query is working on db management applications like postico.
@yahu1031 I don't understand these issues' points, #432 (comment) didn't work for me, and #426 needs PR I think. So there is no fix for this issue now and I have to wait for the PR, am I right? Thanks, @yahu1031 for answering.
You can do one thing. Place a debugger there and see what is the data you get and runtime type. As the issue states it is null, we need a deserializer for Null data type too. Check if you have that in serverpod deserialize package. I will update it once I check. @alizera
It's currently not supported to return dynamic objects from Serverpod. You will need to specify a serializable type (the ones you create in the yaml-files). It's possible we can add support for this in the future.
Thanks dear @vlidholt and @yahu1031
If I get your points and example project correctly:
1- I created a new module called serverpod_test_shared (actually copied it from the example project) and added it to my server and client dependencies
2- Add serverpod_flutter: ^0.9.21 into this modules dependencies
3- Modify the FreezedCustomClass that already exists in this shared module and shape it as I wish to get from my function call:
@freezed
class FreezedCustomClass with _$FreezedCustomClass {
const factory FreezedCustomClass({
required int id1,
required int id2,
required double sum,
}) = _FreezedCustomClass;
factory FreezedCustomClass.fromJson(
Map<String, Object?> json,
SerializationManager serializationManager,
) =>
_$FreezedCustomClassFromJson(json);
}
My query result on SQL app:
4- Run flutter pub get and run the build_runner to generate the freezed class of FreezedCustomClass
5- Modify my endpoint:
Future<List<FreezedCustomClass>> fetchMatchedCity(Session session) async {
session.log("querying match...");
final start = DateTime.now().millisecond;
final result = await session.db.query(""" select id1, id2, sum(score) from (
select t1.id as id1 , t2.id as id2, 1 as score from city as t1, city as t2 where t1.a1 = t2.a1 and t1.id <> t2.id union all
select t1.id as id1 , t2.id as id2, 1 as score from city as t1, city as t2 where t1.a2 = t2.a2 and t1.id <> t2.id
) as final
where id1 > id2
group by (id1, id2) order by sum(score) desc """);
return result as List<FreezedCustomClass>;
}
6- Call it from my app and now a new error happens:
My query is working properly on my SQL app. Can you please help me with this? Or fix me if I'm wrong? Thank you guys for your awesome job and support ❤️
I didn't get exactly that point 2, but to check what the error is, please head over to the logs table in the DB and check for the ID-172 👉🏻 Call log id: 172, statusCode = 500 as it mentioned. @alizera
@yahu1031 Here is the error in serverpod_session_log id 172:
172 default 2023-01-04 10:46:55.521242 city fetchMatchedCity 0.03583 0 FALSE type '_PostgreSQLResult' is not a subtype of type 'List<FreezedCustomClass>' in type cast #0 CityEndpoint.fetchMatchedCity (package:hlafit_server/src/endpoints/city_endpoint.dart:91:19) <asynchronous suspension> #1 EndpointDispatch.handleUriCall (package:serverpod/src/server/endpoint_dispatch.dart:111:20) <asynchronous suspension> #2 Server._handleRequest (package:serverpod/src/server/server.dart:221:18) <asynchronous suspension> 2023-01-04 10:46:55.521242
@yahu1031 I understood the error, but I don't know how to fix it. At the end line of my endpoint method, I cast it to List<FreezedCustomClass> that may cause the error, but before it, it was List<List<dynamic>> that didn't work either.
Can you please help me to fix it? I think I'm missing something stupidly easy.
@alizera type casting won't work all the time cause the API endpoint query is not returning the FreezedCustomClass, It returns List<List<dynamic>>. List<List> cannot be typecasted as custom models/Objects. Hope this will clear your doubt.
I think I'm missing something stupidly easy.
Not actually cause many will get into issues at this point by directly typecasting the response. (Even I do sometimes 🤣)
Dear @yahu1031, I know what you're saying but I don't know what to do about my issue!!
Please look at my first comment, I was using List<List<dynamic>> as the return type of the method and I was getting deserialization error!
I think I can't get the idea behind serialization (I've read its documentation twice and yet... I don't get it).
Finally, you can see my whole code and database and query and the result of the query (that consists of 2 int and one double columns), can you give me a straightforward solution, please? 🥺
IS because it was getting null at that time. But later it was having the result(non-null value) but is not castable. That was the issue you get. Can you post the result here? Or you can contact me on Twitter/LinkedIn. So we can collab.
We have not revisited this in a while, Is this still an issue or can we close this? There has been som major work regarding serialization and database communication to stabilize the interface.
Activity
yahu1031 commentedon Jan 2, 2023
Similar/duplicates of #426 #432
alizera commentedon Jan 3, 2023
@yahu1031 I don't understand these issues' points, #432 (comment) didn't work for me, and #426 needs PR I think. So there is no fix for this issue now and I have to wait for the PR, am I right? Thanks, @yahu1031 for answering.
yahu1031 commentedon Jan 3, 2023
You can do one thing. Place a debugger there and see what is the data you get and runtime type. As the issue states it is null, we need a deserializer for Null data type too. Check if you have that in serverpod deserialize package. I will update it once I check. @alizera
vlidholt commentedon Jan 3, 2023
It's currently not supported to return
dynamicobjects from Serverpod. You will need to specify a serializable type (the ones you create in the yaml-files). It's possible we can add support for this in the future.alizera commentedon Jan 4, 2023
Thanks dear @vlidholt and @yahu1031
If I get your points and example project correctly:
1- I created a new module called
serverpod_test_shared(actually copied it from the example project) and added it to myserverandclientdependencies2- Add
serverpod_flutter: ^0.9.21into this modules dependencies3- Modify the
FreezedCustomClassthat already exists in this shared module and shape it as I wish to get from my function call:My query result on SQL app:

4- Run
flutter pub getand run thebuild_runnerto generate thefreezedclass ofFreezedCustomClass5- Modify my endpoint:
6- Call it from my app and now a new error happens:
My query is working properly on my SQL app. Can you please help me with this? Or fix me if I'm wrong? Thank you guys for your awesome job and support ❤️
yahu1031 commentedon Jan 4, 2023
I didn't get exactly that
point 2, but to check what the error is, please head over to the logs table in the DB and check for theID-172👉🏻Call log id: 172, statusCode = 500as it mentioned. @alizeraalizera commentedon Jan 4, 2023
@yahu1031 Here is the error in
serverpod_session_logid 172:yahu1031 commentedon Jan 4, 2023
Check with this please,
type '_PostgreSQLResult' is not a subtype of type 'List<FreezedCustomClass>' in type castalizera commentedon Jan 4, 2023
@yahu1031 I understood the error, but I don't know how to fix it. At the end line of my endpoint method, I cast it to
List<FreezedCustomClass>that may cause the error, but before it, it wasList<List<dynamic>>that didn't work either.Can you please help me to fix it? I think I'm missing something stupidly easy.
yahu1031 commentedon Jan 4, 2023
@alizera type casting won't work all the time cause the API endpoint query is not returning the
FreezedCustomClass, It returnsList<List<dynamic>>.List<List>cannot be typecasted as custom models/Objects. Hope this will clear your doubt.Not actually cause many will get into issues at this point by directly typecasting the response. (Even I do sometimes 🤣)
Hope this solves your issue.
alizera commentedon Jan 4, 2023
Dear @yahu1031, I know what you're saying but I don't know what to do about my issue!!
Please look at my first comment, I was using
List<List<dynamic>>as the return type of the method and I was gettingdeserializationerror!I think I can't get the idea behind serialization (I've read its documentation twice and yet... I don't get it).
Finally, you can see my whole code and database and query and the result of the query (that consists of 2 int and one double columns), can you give me a straightforward solution, please? 🥺
Thank you again.
yahu1031 commentedon Jan 4, 2023
@alizera I can actually help you.
IS because it was getting null at that time. But later it was having the result(non-null value) but is not castable. That was the issue you get. Can you post the result here? Or you can contact me on Twitter/LinkedIn. So we can collab.
SandPod commentedon Sep 2, 2024
We have not revisited this in a while, Is this still an issue or can we close this? There has been som major work regarding serialization and database communication to stabilize the interface.