flagsmith
flagsmith copied to clipboard
JS crashing when comparing complex environments
@kyle-ssg I will add you to this organisation
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'enabled')
at CompareEnvironmentsPage.js:53:45
at e.exports (_arrayEach.js:15:1)
at Object.e.exports [as each] (forEach.js:37:1)
at CompareEnvironmentsPage.js:47:15
This was caused by one of the environments not having feature states for all features in the project.
I have manually resolved this for the given project now but I am not sure what caused it in the first place. The project had 235 features in it at the time and creating a new environment will therefore have to run 570 queries to create the feature states and feature state values. It could be that something went wrong in this process although I am suspicious of this theory given that everything should be wrapped in a transaction.
More investigation needed.
For reference, here are some example of the queries that I used to resolve it manually:
To identify the differences between environments
select e.id, e.name, e.api_key, count(fs.id) as "num feature states"
from environments_environment e
left join features_featurestate fs on e.id = fs.environment_id
inner join projects_project p on p.id = e.project_id
where p.id = <project id>
and fs.identity_id is null
and fs.feature_segment_id is null
group by e.id;
To identify the missing features
select f.*, "fs".*
from features_featurestate "fs"
inner join environments_environment e on e.id = "fs".environment_id
inner join projects_project p on p.id = e.project_id
inner join features_feature f on f.id = "fs".feature_id
where e.id = <id of environment with all feature states>
and "fs".identity_id is null
and "fs".feature_segment_id is null
and f.id not in (
select f.id
from features_featurestate "fs"
inner join features_feature f on f.id = "fs".feature_id
where "fs".environment_id = <id of environment with missing feature states>
and "fs".identity_id is null
and "fs".feature_segment_id is null
);
To actually resolve the differences
begin;
insert into features_featurestate (enabled, environment_id, feature_id, identity_id, feature_segment_id)
select default_enabled as "enabled", <environment id> as "environment_id", id as "feature_id", null as "identity_id", null as "feature_segment_id"
from features_feature f
where id in (<feature ids>);
insert into features_featurestatevalue ("type", "feature_state_id")
select 'unicode' as "type", id as "feature_state_id"
from features_featurestate "fs"
where feature_id in (<feature ids>)
and environment_id = <environment id>
and identity_id is null
and feature_segment_id is null;
commit;
The following query should return any projects / environments that are exhibiting the same issue. Note that it returns no results in production (but does return results in staging - due to the versions logic that exists in staging now).
select p.id as "project id", p.name as "project name", e.id as "environment id", e.name as "environment name"
from projects_project p
left join environments_environment e on p.id = e.project_id
where e.id in (
select sub1.environment_id
from (
select e.id as "environment_id", count("fs".id)
from environments_environment e
left join features_featurestate "fs" on e.id = "fs".environment_id and "fs".identity_id is null and "fs".feature_segment_id is null
group by e.id
having count("fs".id) <> (select count(f.id) from features_feature f where f.project_id = e.project_id)
) as sub1
);