microsoft / BCApps

Repository for collaboration on Microsoft Dynamics 365 Business Central applications.
https://microsoft.github.io/BCApps/
MIT License
289 stars 140 forks source link

[Bug]: AFS ListDirectory errors if folder empty #1535

Closed ikickicts closed 15 hours ago

ikickicts commented 1 month ago

Describe the issue

Within the Azure File Services API an error occurs when reading the contents of an empty folder.

The AFS Directory Content does not exists. Identification fields and values: Entry No: '0'

The issue appears to be in the ListDirectory function of the AFS File Client Impl codeunit. It attempts to read the contents of a folder into the AFS Directory Content, then it updates the "Next Marker" field on the record before modifying. If the folder is empty, then the AFS Directory Content record does not exist, so the Modify fails

This issue only started occurring in BC24.2

Expected behavior

Calling the ListDirectory function should not error if the folder is empty.

Steps to reproduce

Using the AFS File Client codeunit, call the ListDirectory function, passing in the name of the folder to read, and the AFS DirectoryContent table

    FromAFSFileClient.Initialize(AzureStorageSetup."Account Name", FileShare, Authorization);

    if FilePrefix <> '' then begin
        AFSOptionalParameters.Prefix(FilePrefix);
        AFSOperationResponse := FromAFSFileClient.ListDirectory(FolderName, true, TempAFSDirectoryContent, AFSOptionalParameters);
    end else
        AFSOperationResponse := FromAFSFileClient.ListDirectory(FolderName, TempAFSDirectoryContent);
    if not AFSOperationResponse.IsSuccessful() then
        Error(Format(AFSOperationResponse.GetError()));

If the folder is not empty, then the list of files is returned in the TempADSDirectoryContent table. If the folder is empty, the error occurs

Additional context

No response

I will provide a fix for a bug

DennyHW commented 1 month ago

Please fix it ASAP even in v. 24.4 because is blocking a lot of custom features. The error also occurs if I try to get the content list of an empty directory (without files inside)

TCracco commented 4 days ago

Any news on when this issue will be resolved?

JesperSchulz commented 1 day ago

@ikickicts, you suggested that you will add a fix for this issue. Is that still the plan?

DennyHW commented 1 day ago

This fix has been applied in BC25 build only.

Fixes https://github.com/microsoft/BCApps/issues/1409

Fixes AB#540616

immagine

immagine

Same issue, same solution.

JesperSchulz commented 15 hours ago

This fix has been applied in BC25 build only.

Fixes #1409

Fixes AB#540616

immagine

immagine

Same issue, same solution.

Thanks a lot, @DennyHW! Great that you're able to help keeping the overview 💪 In that case I will close this issue as a duplicate of #1409. At this point there's little sense in backporting, as the next release train I can jump on anyway is version 25 in October. The september one is a wrap.

DennyHW commented 15 hours ago

Yes, but with the new policy in upgrade timeline, some environments may be upgraded in 5 months starting from October. Please backport the fix.

I remember thar 24.0 had no issue. The issue was introduced in 24.2 but fixed only on 25.x.

It's one line of code... please consider backporting.

JesperSchulz commented 15 hours ago

I'll see what I can do. Maybe I can squeeze it into 24.5, as no strings were changed.

JesperSchulz commented 15 hours ago

Here you go: https://github.com/microsoft/BCApps/pull/1886