Skip to content
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

Bug in expiration date for end of month - it updates to previous month #1592

Open
dlpzx opened this issue Sep 30, 2024 · 5 comments · May be fixed by #1594
Open

Bug in expiration date for end of month - it updates to previous month #1592

dlpzx opened this issue Sep 30, 2024 · 5 comments · May be fixed by #1594
Assignees
Labels
priority: high type: bug Something isn't working

Comments

@dlpzx
Copy link
Contributor

dlpzx commented Sep 30, 2024

Describe the bug

When running the integration tests (current ones) the tests/modules/s3_datasets_shares/test_share.py::test_submit_share_extension_request_with_auto_approval test fails: https://github.com/data-dot-all/dataall/actions/runs/11102824595/job/30843468276?pr=1573

The issue seems to be in the expiration date set to test the share expiration dates on share submission.

Checking the logs of getShareObject after the request is submitted:
'expiryDate': '2024-09-30 00:00:00', 'requestedExpiryDate': '2024-09-30 00:00:00', ---> which means that share.requestedExpiryDate < datetime.today() is True so the test falls into this block from the share_object_service:

            if dataset.enableExpiration and share.requestedExpiryDate and share.requestedExpiryDate < datetime.today():
                raise Exception(
                    'Cannot approve share extension since its it past the requested expiration date. Please reject this share and submit a new share request'
                )

The dataset expiration settings are defined in the fixture dataset_with_expiration_with_autoapproval

        enableExpiration=True,
        expirySetting='Monthly',
        expiryMinDuration=1,
        expiryMaxDuration=3,
    )

The issue might be in backend/dataall/modules/shares_base/services/share_object_service.py:327 where we calculate the expiration date. We should be trying to set it to October 31 not to September 30.

            # in this case expirationPeriod = 1, expirySetting = Monthly
            monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod - 1)
            monthEndDay = calendar.monthrange(monthlyCalculatedDate.year, monthlyCalculatedDate.month)[1]
            shareExpiryDate = datetime(monthlyCalculatedDate.year, monthlyCalculatedDate.month, monthEndDay)

Today is Sept 30. the line to calculate the end of month date is wrong as the delta is 0 so monthlyCalculatedDate = 30/09/2024 + relativedelta(months=1 - 1) = 30/09/2024

How to Reproduce

Run tests as it is done automatically in our PRs. One example of the failure is in this PR: https://github.com/data-dot-all/dataall/actions/runs/11102824595/job/30843468276?pr=1573

Expected behavior

No response

Your project

No response

Screenshots

No response

OS

na

Python version

na

AWS data.all version

2.6.0

Additional context

No response

@dlpzx dlpzx added type: bug Something isn't working priority: high labels Sep 30, 2024
@dlpzx dlpzx self-assigned this Sep 30, 2024
@dlpzx dlpzx changed the title Expiration date for submit share extension test is already expired Tests for dataset with autoapproval with shares expiration date failing Sep 30, 2024
@dlpzx dlpzx changed the title Tests for dataset with autoapproval with shares expiration date failing Bug in expiration date for end of month - it updates to previous month Sep 30, 2024
@dlpzx
Copy link
Contributor Author

dlpzx commented Sep 30, 2024

@TejasRGitHub I think we can use your input here. Why is there a - 1 in the calculation of the time deltas?

@TejasRGitHub
Copy link
Contributor

TejasRGitHub commented Sep 30, 2024

Hi @dlpzx , Thanks for spotting this issue.

The -1 was added to make sure that we are not allocating more than required months on the expiration.

For example,
If someone requested share expiration for 1 month and the current date was 2nd Sept, then in that case monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod - 1) would yield 0 and thus the end of month will be set as expiration.
With out -1, the expiration date will be set to end of Oct .

But with the bug you just raised I got to see how this is problematic.

Proposed change in share expiration:

In this scenario ( represented in the bug filed above ) , if a user requests a share at the end of the month, then the user should be granted expiration till the end of the next month.
But in the scenario when the user is requesting for 1 month share expiration and the current date is 1st Sept , he should be given expiration till the end of the month

Calculation can be modified to :

if currentDate > Total Days in Month / 2: 
    monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod)
else:
    monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod - 1)

@dlpzx
Copy link
Contributor Author

dlpzx commented Sep 30, 2024

I am implementing this fix; with the proposal the behavior is that if we are in the first half of the month then we extend until end of month and if we are in the second half of the month we extend until end of next month?

@TejasRGitHub
Copy link
Contributor

I am implementing this fix; with the proposal the behavior is that if we are in the first half of the month then we extend until end of month and if we are in the second half of the month we extend until end of next month?

Yes. you are right

@TejasRGitHub
Copy link
Contributor

TejasRGitHub commented Sep 30, 2024

@dlpzx , also for this one,

-xxxxxx----
Checking the logs of getShareObject after the request is submitted:
'expiryDate': '2024-09-30 00:00:00', 'requestedExpiryDate': '2024-09-30 00:00:00' ---> which means that share.requestedExpiryDate < datetime.today() is True so the test falls into this block from the share_object_service:

            if dataset.enableExpiration and share.requestedExpiryDate and share.requestedExpiryDate < datetime.today():
                raise Exception(
                    'Cannot approve share extension since its it past the requested expiration date. Please reject this share and submit a new share request'
                )

-xxxxx----

Just wanted to clarify that no changes needed in this . In my previous message I erred and also proposed changes in this but it it not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high type: bug Something isn't working
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

2 participants