1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

fix: make sure we have a user in event store (#3072)

## About the changes
Spotted some issues in logs:
```json
{
  "level":"warn",
  "message":"Failed to store \"feature-environment-variants-updated\" event: error: insert into \"events\" (\"created_by\", \"data\", \"environment\", \"feature_name\", \"pre_data\", \"project\", \"tags\", \"type\") values (DEFAULT, $1, $2, $3, $4, $5, $6, $7) returning \"id\", \"type\", \"created_by\", \"created_at\", \"data\", \"pre_data\", \"tags\", \"feature_name\", \"project\", \"environment\" - null value in column \"created_by\" violates not-null constraint",
  "name":"lib/db/event-store.ts"
}
```

In all other events we're doing the following:
b7fdcd36c0/src/lib/services/segment-service.ts (L80)

So this is just mimicking that to quickly release a patch, but I'll look
into a safer (type-checked) solution so this problem does not happen
again
This commit is contained in:
Gastón Fournier 2023-02-09 11:01:39 +01:00 committed by GitHub
parent b7fdcd36c0
commit b76e66fc1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -1331,7 +1331,7 @@ class FeatureToggleService {
featureName: string, featureName: string,
environment: string, environment: string,
newVariants: IVariant[], newVariants: IVariant[],
createdBy: string, user: User,
oldVariants?: IVariant[], oldVariants?: IVariant[],
): Promise<IVariant[]> { ): Promise<IVariant[]> {
await variantsArraySchema.validateAsync(newVariants); await variantsArraySchema.validateAsync(newVariants);
@ -1350,7 +1350,7 @@ class FeatureToggleService {
featureName, featureName,
environment, environment,
project: projectId, project: projectId,
createdBy, createdBy: user.email || user.username,
oldVariants: theOldVariants, oldVariants: theOldVariants,
newVariants: fixedVariants, newVariants: fixedVariants,
}), }),
@ -1383,7 +1383,7 @@ class FeatureToggleService {
featureName, featureName,
environment, environment,
newVariants, newVariants,
user.username, user,
oldVariants, oldVariants,
); );
} }
@ -1405,7 +1405,7 @@ class FeatureToggleService {
featureName, featureName,
environments, environments,
newVariants, newVariants,
user.username, user,
); );
} }
@ -1414,7 +1414,7 @@ class FeatureToggleService {
featureName: string, featureName: string,
environments: string[], environments: string[],
newVariants: IVariant[], newVariants: IVariant[],
createdBy: string, user: User,
): Promise<IVariant[]> { ): Promise<IVariant[]> {
await variantsArraySchema.validateAsync(newVariants); await variantsArraySchema.validateAsync(newVariants);
const fixedVariants = this.fixVariantWeights(newVariants); const fixedVariants = this.fixVariantWeights(newVariants);
@ -1436,7 +1436,7 @@ class FeatureToggleService {
featureName, featureName,
environment, environment,
project: projectId, project: projectId,
createdBy, createdBy: user.email || user.username,
oldVariants: oldVariants[environment], oldVariants: oldVariants[environment],
newVariants: fixedVariants, newVariants: fixedVariants,
}), }),

View File

@ -433,6 +433,7 @@ test('If change requests are enabled, cannot change variants without going via C
}); });
test('If CRs are protected for any environment in the project stops bulk update of variants', async () => { test('If CRs are protected for any environment in the project stops bulk update of variants', async () => {
const user = { email: 'test@example.com', username: 'test-user' } as User;
const project = await stores.projectStore.create({ const project = await stores.projectStore.create({
id: 'crOnVariantsProject', id: 'crOnVariantsProject',
name: 'crOnVariantsProject', name: 'crOnVariantsProject',
@ -476,7 +477,7 @@ test('If CRs are protected for any environment in the project stops bulk update
const toggle = await service.createFeatureToggle( const toggle = await service.createFeatureToggle(
project.id, project.id,
{ name: 'crOnVariantToggle' }, { name: 'crOnVariantToggle' },
'test-user', user.username,
); );
const variant: IVariant = { const variant: IVariant = {
@ -495,7 +496,7 @@ test('If CRs are protected for any environment in the project stops bulk update
toggle.name, toggle.name,
[enabledEnv.name, disabledEnv.name], [enabledEnv.name, disabledEnv.name],
[variant], [variant],
'test-user', user,
); );
const newVariants = [ const newVariants = [