Temporary record parameters should always be checked for being temporary #732
christophstuber
started this conversation in
New Rule
Replies: 1 comment
-
This is a good one. 👍 A (maybe obvious) condition is that the table of the parameter does not have |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When passing a temporary record as a parameter, you almost always specify the parameter to be by var. However, when you do that, the temporary property becomes more of a suggestion. If the variable you pass to the function is not temporary, the parameter will not be temporary either.
This example shows the problem:
Since you normally don't want to use triggers with temporary records, it's almost always DeleteAll() without the RunTrigger or false. This means safety checks for deletes are not run.
Checking the caller with static code analysis would be a first step, but the only safe version at runtime (especially for public functions) is to check IsTemporary and either exit or Error(). I prefer Error, as the method is designed to be used only with temporary records.
Beta Was this translation helpful? Give feedback.
All reactions