-
Notifications
You must be signed in to change notification settings - Fork 167
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
Source generation doesn't support non-nullable object types #3085
Comments
The problem is that properties linking to realm objects are inherently nullable. Since you can always do something like: RealmNamedFileUsage usage = ...;
realm.Remove(usage.File); Now, |
I completely understand that from a safety perspective. But I do wonder if some middle-ground can be offered as we value non-nullable specs on a lot of our models (and haven't had this go wrong for us.. yet). |
@papafe perhaps we can offer this as a config option? I.e. allow users to explicitly enable usage of non-nullable link properties? I guess we could still return null on our end and have them deal with the consequences 😅 |
I would prefer the same as any on-the-wire deserialization API does (e.g. System.Text.Json, etc), namely you can declare the nullability however you want but that doesn't guarantee anything about the actual data. Its still up to the clients to not corrupt the underlying, and allowing the programmer to specify that it shouldnt be null avoids a lot of noisy error handling throughout the entire codebase. |
I think we can offer that as a config option. We have several things in the pipeline, including full support for nullability annotations in the model definition (#2982). |
I'm definitely in favor of moving to nullability declarations (and nullable reference types) as the source of truth and avoiding the need for |
@J-Swift Yes, that is the plan. I suppose that there are different preferences on this 😄 |
This should be addressed by #3172 which should go into our next release. |
I think we're reading this option from the global config, so you should put it there. See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig for more details. |
I see, this does indeed work! May be worth updating the link here to point to the correct anchor on that page - as it stands I misunderstood which config file was supported. Now the remaining issues look to be inspection rules we have triggering inside the source generated files:
I believe this may be due to our project settings for the inspections, and if that's the case there may need to be a method of disabling this for realm sourcegen. |
Can you post the generated code that's triggering these warnings? I'm afraid |
Here's the generated code from the above run: |
For anyone interested, to disable inspection rules in source generators, it looks like you basically have to disable at a I'm facing some remaining issues with source generation but I'll open a new discussion to keep things clean, as they are not nullability related. |
What happened?
We are keen to switch to the new source generator, but are blocked by it not supporting non-nullable object types. We have been using realm with non-nullable object types for a good year and it definitely works well, so I would hope that this can be supported by the source generator.
Currently it is disabled via this check:
realm-dotnet/Realm/Realm.SourceGenerator/InfoClasses.cs
Lines 250 to 254 in a7b8f3a
I'm not sure if this is to be considered a bug or feature request, but it's a blocker for us to use source generation unfortunately.
Repro steps
Version
6.x
What SDK flavour are you using?
Local Database only
What type of application is this?
Other
Client OS and version
10.18.0
Code snippets
An example of a class that would work previously:
Our codebase branch with all changes applied that we hope would make source generation work correctly: https://github.com/ppy/osu/compare/master...peppy:osu:realm-source-gen?expand=1
Stacktrace of the exception/crash you're getting
Program.cs(19, 5): [RLM010] RealmNamedFileUsage.File has type RealmFile, that does not support the assigned nullability annotiation.
The text was updated successfully, but these errors were encountered: