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

offtopicnames active attribute and support for PUT and PATCH request #508

Merged
merged 26 commits into from
Dec 28, 2021

Conversation

RohanJnr
Copy link
Member

@RohanJnr RohanJnr commented May 19, 2021

closes #490
linked to python-discord/bot#1568

Changes

  • New attribute active for OffTopicName.
  • Can query based on the active attribute of OffTopicName.
  • Patch and Put support for OffTopicName.
  • DETAIL view support for OffTopicName.
  • Tests modified as required.

@RohanJnr RohanJnr marked this pull request as ready for review June 9, 2021 21:03
@coveralls
Copy link

coveralls commented Jun 9, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling c4e2eda on RohanJnr:otn_softdel into b52587d on python-discord:main.

Copy link
Member

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

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

This looks great! A small comment. Nice use of Walrus.

pydis_site/apps/api/serializers.py Outdated Show resolved Hide resolved
@jchristgit
Copy link
Member

@RohanJnr thanks for the docstring update.

There's currently an error in CI due to conflicting migrations:

CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0070_auto_20210519_0545, 0071_increase_message_content_4000 in api).
20
To fix them run 'python manage.py makemigrations --merge'

Could you look into fixing this?

It also seems the branch needs to be updated.

@RohanJnr
Copy link
Member Author

Looks like I forgot to push the new commits, haha. Will do when I am at my pc tmw 👍

Copy link
Member

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

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

I like this. I have a few questions, but apart from that, I like this.

pydis_site/apps/api/serializers.py Outdated Show resolved Hide resolved
pydis_site/apps/api/serializers.py Outdated Show resolved Hide resolved
pydis_site/apps/api/serializers.py Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py Outdated Show resolved Hide resolved
@RohanJnr
Copy link
Member Author

RohanJnr commented Nov 4, 2021

Thanks for the review again @jchristgit :D, I will work on them asap.

@Xithrius Xithrius added area: API Related to or causes API changes area: backend Related to internal functionality and utilities priority: 2 - normal Normal Priority type: enhancement Changes or improvements to existing features labels Nov 12, 2021
Copy link
Member

@jchristgit jchristgit left a comment

Choose a reason for hiding this comment

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

Solid work. Thank you!

One minor suggestion for the future: Instead of using the autogenerated names by Django for migrations (like auto_20210519_0545), it's nice to have a short name describing the migration.

@D0rs4n
Copy link
Member

D0rs4n commented Nov 27, 2021

Hey! Would you mind opening an issue (and a PR if you'd like to) in the API repository regarding the database model changes? @RohanJnr

@jchristgit jchristgit requested review from Bluenix2 and removed request for jb3, Akarys42 and Den4200 December 11, 2021 12:52
@Bluenix2
Copy link
Member

@RohanJnr thanks for the docstring update.

There's currently an error in CI due to conflicting migrations:

CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0070_auto_20210519_0545, 0071_increase_message_content_4000 in api).
20
To fix them run 'python manage.py makemigrations --merge'

Could you look into fixing this?

It also seems the branch needs to be updated.

The fix for this was the 0072_merge migration I see correct?

Do want to give 0070_auto_20210519_0545 a more meaningful name?

@jchristgit
Copy link
Member

The fix for this was the 0072_merge migration I see correct?

Yes

Do want to give 0070_auto_20210519_0545 a more meaningful name?

I think due to the dependencies of the other migrations on this migration this will get a bit hairy, unfortunately :(

@Bluenix2
Copy link
Member

Bluenix2 commented Dec 25, 2021

The behaviour of the PATCH/PUT method is a little unexpected. You can send a request to /api/bot/off-topic-channel-names/existing-name with the body {"name": "another-one"}... which causes another off-topic name to be created. Should this be changed or should I approve? Considering that is my only complaint..

That said when using PATCH correctly it worked nicely and made the names no longer show up when specifying ?active=true (as expected from the changes by this PR).

@RohanJnr
Copy link
Member Author

Practically, The PATCH method allows modification of all fields on the model. We could leave it as it is as we will only be patching the active field. If we really want to restrict the PATCH to 1 field only, i.e, the active field, we can add a check to make sure the request body only contains the active field. But, I am not sure if we should have this check or leave it as it is?

@Bluenix2
Copy link
Member

Practically, The PATCH method allows modification of all fields on the model. We could leave it as it is as we will only be patching the active field. If we really want to restrict the PATCH to 1 field only, i.e, the active field, we can add a check to make sure the request body only contains the active field. But, I am not sure if we should have this check or leave it as it is?

What is unexpected is the fact that you can create a new off-topic-name by PUTting (this is primarily what I tried, don't remember if it works the same with PATCH) to an existing off-topic-name. I don't really understand what even caused the support for these new methods as it is done implicitly by Django so I am not sure how much it would take to change this behaviour.

@RohanJnr
Copy link
Member Author

RohanJnr commented Dec 25, 2021 via email

Copy link
Member

@Bluenix2 Bluenix2 left a comment

Choose a reason for hiding this comment

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

I think what we discussed is fine then if it seems like it would be a lot of code to change it - it's not a big deal. Thanks for this, let's get it merged!

@jchristgit jchristgit merged commit 4ab7972 into python-discord:main Dec 28, 2021
@jchristgit

This comment was marked as outdated.

@jchristgit
Copy link
Member

Sorry, wrong project...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Related to or causes API changes area: backend Related to internal functionality and utilities priority: 2 - normal Normal Priority type: enhancement Changes or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-roll off topic names backend changes.
6 participants