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

@W-14603959 - Update backend deps and test failure fixes #2154

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

vsbharath
Copy link
Contributor

No description provided.

@vsbharath vsbharath requested a review from a team as a code owner December 11, 2023 20:50
Copy link
Contributor

@jstvz jstvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for slogging through these. Some changes requested, including sticking to Django 4.2.x. (⚠️: You may hit pennersr/django-allauth#3564 if you also update django-allauth to 0.59.0)

Comment on lines 718 to 722
def save(self, *args, **kwargs):
obj = super().save(*args, **kwargs)
self.update_status()
return super().save(*args, **kwargs)
return obj

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django 4.1 introduces a change where using reverse foreign keys before saving an object raises a ValueError. Since the update_status method interacts with related objects, as seen in methods like should_update_review, we have issues with reverse foreign key lookups.

You're correct that calling super().save() to ensure the Epic instance has an ID before update_status is the right fix. But the way it's written now, the status gets updated but not saved in the database.

    def save(self, *args, **kwargs):
        if not self.id:
            super().save(*args, **kwargs)
        self.update_status()
        return super().save()

This code makes sure that if the Epic is new, we save it before updating the status. By not repeating *args, **kwargs in the final save, we avoid duplicating related objects.

# via -r requirements/prod.in
django==4.0.6
django==5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to the LTS for now. You can restrict which version of Django we use in prod.in:

Django~=4.2.0 # LTS

(Where ~= means compatible release.)

Comment on lines 6 to 29
@pytest.fixture
def dummy():
app = SocialApp.objects.create(
provider=CustomSalesforceProvider.id,
name=CustomSalesforceProvider.id,
client_id="app123id",
key=CustomSalesforceProvider.id,
secret="dummy",)
return app


@pytest.mark.django_db
def test_get_auth_params(rf, dummy):
request = rf.get("/")
result = CustomSalesforceProvider(request).get_auth_params(request, None)
result = CustomSalesforceProvider(request, dummy).get_auth_params(request, None)
assert "prompt" in result and result["prompt"] == "login"


@pytest.mark.django_db
def test_extract_uid(rf):
request = rf.get("/")
provider = CustomSalesforceProvider(request)
provider = CustomSalesforceProvider(request, dummy)
result = provider.extract_uid({"organization_id": "ORG", "user_id": "USER"})
assert result == "ORG/USER"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. Let's just use the factory_boy fixture instead:

@pytest.mark.django_db
def test_get_auth_params(rf, social_app_factory):
    request = rf.get("/")
    app = social_app_factory(
        name=CustomSalesforceProvider.id,
        provider=CustomSalesforceProvider.id,
    )
    result = CustomSalesforceProvider(request, app).get_auth_params(request, None)
    assert "prompt" in result and result["prompt"] == "login"

@@ -42,7 +42,7 @@ def test_queryset__deleted(self, epic_factory):

args = (
None,
{"deleted_at": "true"},
{"deleted_at": ["true"]},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can set this aside until we do move to Django 5x:

Suggested change
{"deleted_at": ["true"]},
{"deleted_at": "true"},

@vsbharath
Copy link
Contributor Author

@jstvz Thanks for the detailed review. Addressed the review comments and got to know the usage of factory_boy now.

@vsbharath vsbharath requested a review from jstvz December 15, 2023 18:19
@jstvz jstvz merged commit c12b902 into main Dec 15, 2023
5 checks passed
@jstvz jstvz deleted the update-deps-python branch December 15, 2023 20:20
vsbharath added a commit that referenced this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants