getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
782 stars 313 forks source link

SwiftData: NSCompoundPredicate predicateOperatorType: unrecognized selector sent to instance #3553

Open sowenjub opened 6 months ago

sowenjub commented 6 months ago

Platform

iOS

Environment

Develop

Installed

Swift Package Manager

Version

8.18

Did it work on previous versions?

no

Steps to Reproduce

Use a SwiftData predicate that generates a ternary operator, in my case the code looks something like this

       let kinds: [AwardKind] = [.firstTime, .nightOwl]
       var descriptor = FetchDescriptor<Award>()
        let rawKinds = kinds.map(\.rawValue)

        descriptor.predicate = #Predicate<Award> { award in
            if let rawKind = award.rawKind {
                award.claimDate == nil && rawKinds.contains(rawKind)
            } else {
                award.claimDate == nil
            }
        }

Expected Result

Not crash

Actual Result

Crash in - (NSString *)comparisonPredicateDescription:(NSComparisonPredicate *)predicate because - (NSString *)predicateOperatorTypeDescription:(NSPredicateOperatorType)operator doesn't support TERNARY operator

Are you willing to submit a PR?

No response

kahest commented 6 months ago

Hey @sowenjub - I don't see a reason to believe this is caused by Sentry, can you explain? Did you try to reproduce without Sentry? To me it looks like the predicate and/or how it's used to query might be incorrect.

sowenjub commented 6 months ago

The query worked fine before I added Sentry, and still does if I don't init Sentry or if I disable Core Data tracing in the Sentry options.

The interruption points to Sentry code, the predicate generated by SwiftData includes a TERNARY operator which is not part of the supported operators in the function that crashes.

kahest commented 6 months ago

Ah yes you're right - we'll fix this, thanks for bringing it to our attention

kahest commented 5 months ago

Internal data points: https://sentry.sentry.io/issues/?project=4505469596663808&query=comparisonPredicateDescription&referrer=issue-list&statsPeriod=90d

saulrodeo commented 3 months ago

I also have this issue using SwiftData and compound Predicates:

https://letsrodeo.sentry.io/issues/5092468581/?referrer=alert_email&alert_type=email&alert_timestamp=1711126918556&alert_rule_id=15065067&notification_uuid=663b00cb-dd71-4ded-84cd-86543d085aec&environment=production

It works when sentry is removed