Make sure AppItem is up to date with sycoca when checking isValid()
when an application contained in favorite is uninstalled, the favoritemodel KSycoca databaseChanged connection gets executed before the AppItem own connection, so at that point is still isValid() while is not true.
force its update instead before checking isValid()