microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 245 forks source link

The record YYY should be modified before saving to the database. #6162

Closed GreatScott000 closed 2 years ago

GreatScott000 commented 4 years ago

Describe the bug As with #5665 I am getting a number of these errors even after it has been reported as "fixed". I get

The record AccountingPeriod2 should be modified before saving to the database.

With this code, this is just one of many examples.

    local procedure GetPeriodEnd(PeriodStart: Date): Date;
    var
        AccountingPeriod2: Record "Accounting Period";
    begin
        with AccountingPeriod2 do begin
            SetFilter("Starting Date", '>%1', PeriodStart);
            if FindFirst() then begin
                exit(CalcDate('<-1D>', "Starting Date"));
            end else begin
                exit(CalcDate('<+CM>', PeriodStart));
            end;
        end;
    end;

A clear and concise description of what the bug is.

To Reproduce Steps and to reproduce the behavior: See below, just create the procedure shown

    local procedure GetPeriodEnd(PeriodStart: Date): Date;
    var
        AccountingPeriod2: Record "Accounting Period";
    begin
        with AccountingPeriod2 do begin
            SetFilter("Starting Date", '>%1', PeriodStart);
            if FindFirst() then begin
                exit(CalcDate('<-1D>', "Starting Date"));
            end else begin
                exit(CalcDate('<+CM>', PeriodStart));
            end;
        end;
    end;

Expected behavior No warning when a record is NOT updated

Screenshots None

5. Versions:

dzzzb commented 4 years ago

MS, with the greatest respect: please consider just disabling this diagnostic until it actually works. The number of legitimate cases it could catch seems dwindling compared to the number of false positives people have had to wade through across the months.

mazhelez commented 2 years ago

Thanks for reporting this issue. Sorry we haven’t completed it yet, but we’ve had to prioritize elsewhere. We’re planning to give the CodeCop engine and its rules an overhaul in a future major release. Thanks for your patience.

For this case consider using Pragma Warning Directive.