launchdarkly / node-server-sdk

LaunchDarkly Server-side SDK for Node
Other
79 stars 65 forks source link

Error when updating TestData when calling ifMatch #258

Closed LiamMorrow closed 2 years ago

LiamMorrow commented 2 years ago

Is this a support request? No

Describe the bug When using ifMatch on TestData, there is a circular JSON reference error when calling the update method

To reproduce

const launchDarklyClient = ld.init('not a real key', { updateProcessor: testData, sendEvents: false })
const variationForMatch = testData.flag(featureFlagKey).ifMatch('someCustomKey', 'someKeyValue').thenReturn(false)
testData.update(variationForMatch)

Expected behavior No error

Logs

TypeError: Converting circular structure to JSON
        --> starting at object with constructor 'Array'
        |     index 0 -> object with constructor 'TestDataRuleBuilder'
        |     property '_flagBuilder' -> object with constructor 'TestDataFlagBuilder'
        --- property '_rules' closes the circle
        at JSON.stringify (<anonymous>)
        at TestDataFlagBuilder.Object.<anonymous>.TestDataFlagBuilder.copy (../node_modules/launchdarkly-node-server-sdk/test_data.js:101:53)
        at Function.TestData.td.update (../node_modules/launchdarkly-node-server-sdk/test_data.js:58:58)

SDK version 6.4.2

Language version, developer tools Typescript/node/jest

OS/platform All dev platforms

Additional context Seems to be a circular ref between the rules and the data rule builder

kinyoklion commented 2 years ago

Hello @LiamMorrow,

Thank you for the issue and associated PR.

Thank you, Ryan

kinyoklion commented 2 years ago

Fixed in 6.4.3.