Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheKeyInfo with a numeric jsonValue of 1 returns nil #3414

Closed
davbeck opened this issue Jul 16, 2024 · 4 comments · Fixed by apollographql/apollo-ios-dev#459
Closed

CacheKeyInfo with a numeric jsonValue of 1 returns nil #3414

davbeck opened this issue Jul 16, 2024 · 4 comments · Fixed by apollographql/apollo-ios-dev#459
Assignees
Labels
awaiting response bug Generally incorrect behavior needs investigation planned-next Slated to be included in the next release

Comments

@davbeck
Copy link

davbeck commented Jul 16, 2024

Summary

If an object has an id of 1 and that is used to create CacheKeyInfo, it will return nil. The issue seems to be that it gets cast to a Bool in ObjectData.swift:30. Swift casting will convert any number with a value of 0 or 1 to a Bool when asked ((1 as AnyHashable) as? Bool will resolve to true).

Version

v1.13.0

Steps to reproduce the behavior

I modified test__schemaConfiguration__givenData_whenUnknownType_withCacheKeyInfoForUnknownType_shouldReturnInfoWithTypeName and was able to reproduce the issue with the following:

let object: JSONObject = [
  "__typename": "Omega",
  "id": 1
]

let objectDict = NetworkResponseExecutionSource().opaqueObjectDataWrapper(for: object)
let actual = MockSchemaMetadata.cacheKey(for: objectDict)

expect(actual).to(equal("Omega:1"))

Logs

No response

Anything else?

No response

@davbeck davbeck added bug Generally incorrect behavior needs investigation labels Jul 16, 2024
@calvincestari
Copy link
Member

Hi @davbeck - I don't think that test is failing in the way that you think it is. If you substitute ω for 1 the test fails because the resulting cache key is Omega:1 instead of the expected Omega:ω. That does not mean that CacheKeyInfo is returning nil because otherwise the whole cache key would be nil.

Are you able to replicate this in a standalone sample project that we can use to debug?

@AnthonyMDev AnthonyMDev added this to the Patch Releases (1.x.x) milestone Aug 9, 2024
@AnthonyMDev AnthonyMDev added the planned-next Slated to be included in the next release label Aug 9, 2024
@AnthonyMDev
Copy link
Contributor

We've talked through this and verified this is a bug. We'll look into a fix for the next patch release. Thanks for the report!

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

@calvincestari
Copy link
Member

This is fixed and will be included with the next release.

@calvincestari calvincestari self-assigned this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response bug Generally incorrect behavior needs investigation planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants