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

api : Encoded certain endpoint parameters. #634

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aryanshridhar
Copy link
Member

@aryanshridhar aryanshridhar commented Nov 12, 2020

Rectified parameters in certain api endpoints to deprecate dictionary parameters .

Affected Endpoints :

GET get_profile
POST update_presence
GET get_users
GET get_members
GET get_subscriptions (was named as 'list_subscriptions' until commit).
PATCH mute_topic
POST render_message
POST create_user
PUT update_storage
GET get_storage
POST set_typing_status

As discussed within zulip/zulip#16698

@andersk
Copy link
Member

andersk commented Nov 12, 2020

Deprecating is not the same as removing—we still want to support the old syntax with a warning for some deprecation period.

Also, this is not the only function affected by this issue.

@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch from 228488e to 78a8dcb Compare November 13, 2020 07:58
@aryanshridhar
Copy link
Member Author

Hey @andersk , upon grep -rnw . -e 'list_subscriptions' , I see the following functions calling the list_subscriptions function :

/integrations/jabber/jabber_mirror_backend.py:278:        stream_infos = get_stream_infos("subscriptions", zulipToJabber.client.list_subscriptions)
./integrations/bridge_with_irc/irc_mirror_backend.py:39:        resp = self.zulip_client.list_subscriptions()
./build/lib/integrations/jabber/jabber_mirror_backend.py:278:        stream_infos = get_stream_infos("subscriptions", zulipToJabber.client.list_subscriptions)
./build/lib/integrations/bridge_with_irc/irc_mirror_backend.py:39:        resp = self.zulip_client.list_subscriptions()
./build/lib/zulip/examples/list-subscriptions:21:print(client.list_subscriptions())
./build/lib/zulip/__init__.py:1281:    def list_subscriptions(self, request: Optional[Dict[str, Any]] = None, **kwargs: Any) -> Dict[str, Any]:
./zulip/examples/list-subscriptions:21:print(client.list_subscriptions())
./zulip/__init__.py:1281:    def list_subscriptions(self, request: Optional[Dict[str, Any]] = None, **kwargs: Any) -> Dict[str, Any]:

But none of them have a parameter of {'include_subscribers' : bool_value} . Could you guide me on mentioning the functions that need to be altered due to this issue .

@andersk
Copy link
Member

andersk commented Nov 13, 2020

These all share the same antipattern:

    def get_profile(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def update_presence(self, request: Dict[str, Any]) -> Dict[str, Any]:
    def get_users(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def get_members(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def list_subscriptions(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def mute_topic(self, request: Dict[str, Any]) -> Dict[str, Any]:
    def render_message(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def create_user(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def update_storage(self, request: Dict[str, Any]) -> Dict[str, Any]:
    def get_storage(self, request: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    def set_typing_status(self, request: Dict[str, Any]) -> Dict[str, Any]:

@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch from 78a8dcb to f1a8470 Compare November 13, 2020 16:54
@aryanshridhar aryanshridhar changed the title list_subscriptions: Encoded list_subscriptions parameters. api : Encoded certain endpoint parameters. Nov 13, 2020
@aryanshridhar
Copy link
Member Author

Is there any changes to be made @andersk ? Or should I go ahead to fix failing mypy failures .

Copy link
Contributor

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@aryanshridhar I left some feedback on what you have so far.

zulip/zulip/__init__.py Outdated Show resolved Hide resolved
zulip/zulip/__init__.py Outdated Show resolved Hide resolved
@neiljp
Copy link
Contributor

neiljp commented Nov 13, 2020

@andersk Would a decorator to handle the migration work here, do you think?

@andersk
Copy link
Member

andersk commented Nov 14, 2020

A decorator might have the disadvantage of making the pydoc confusing and the mypy types poor (all mypy can guarantee about a decorator is basically “congratulations, you have a function!”).

A helper function pattern like this would be fine:

def deprecated_request(request: Optional[Dict[str, Any]]) -> Dict[str, Any]:
    if request is not None:
        logger.warning(…)
        return request
    return {}

def list_subscriptions(self, request: Optional[Dict[str, Any]] = None, **kwargs: Any) -> Dict[str, Any]:
    return self.call_endpoint(…, request={**deprecated_request(request), **kwargs})

@neiljp
Copy link
Contributor

neiljp commented Nov 14, 2020

@andersk I agree that this approach is simple - and almost suggested something similar, ie. putting all of the deprecation-migration code together.

Re decorators, I did think mypy could handle them - since we have them annotated in the main repo - though I suppose it's one thing to annotate and another to know what is actually validated via them being present. I'd also have thought @wraps would handle docstrings, and would therefore take it that docstring-consumers like pydoc would be OK too.

@aryanshridhar
Copy link
Member Author

Hey , @andersk @neiljp , Could you review it again ?

@timabbott
Copy link
Member

I think this change makes sense to me -- @aryanshridhar can you rebase this?

I'm a bit reluctant to merge this while we're unable to update python-zulip-api in zulip/zulip, which we'll definitely need to do in order to update documentation for the modified endpoints.

(Or did we resolve that issue and I just didn't notice?)

@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch from 1cf3724 to 9eca925 Compare March 25, 2021 15:42
@zulipbot zulipbot added size: XL and removed size: S labels Mar 25, 2021
@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch from 9eca925 to 7370a8e Compare March 25, 2021 16:15
@zulipbot zulipbot added size: L and removed size: XL labels Mar 25, 2021
@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch 2 times, most recently from 940cd5d to 5abce43 Compare March 25, 2021 16:40
@zulipbot zulipbot added size: XL and removed size: L labels Mar 25, 2021
Rectified the parameters in certain api endpoints to ,
take up default parameters rather than a dictionary.

Affected endpoints:

GET get_profile
POST update_presence
GET get_users
GET get_members
GET get_subscriptions
PATCH mute_topic
POST render_message
POST create_user
PUT update_storage
GET get_storage
POST set_typing_status

As discussed within zulip/zulip#16698.
@aryanshridhar aryanshridhar force-pushed the Fix-list-subscribers_api branch from 5abce43 to 20d2e59 Compare March 25, 2021 16:45
aryanshridhar added a commit to aryanshridhar/zulip that referenced this pull request Mar 25, 2021
In zulip/python-zulip-api#634, certain endpoint parameters
were encoded to make the function callable by passing the arguements,
rather than passing them as a dictionary.

Following api endpoints are affected within the docs:

POST update_presence
GET get_members
PATCH mute_topic
POST render_message
POST create_user
POST set_typing_status
@aryanshridhar
Copy link
Member Author

aryanshridhar commented Mar 25, 2021

Rebased it @timabbott, As far as I remember, there was no further work done related to this pr in zulip/zulip.
Opened zulip/zulip#17804 to update the docs (Converted it to draft until this pr looks fine).

@timabbott
Copy link
Member

I'm going to hold off on this until after #692; let's chat about it next week.

@timabbott
Copy link
Member

@aryanshridhar can you rebase this?

@zulipbot
Copy link
Member

Heads up @aryanshridhar, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants