Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Should the server or client deal with invalid scaling requests? #21

Closed
daveschaefer opened this issue Oct 24, 2012 · 1 comment
Closed

Comments

@daveschaefer
Copy link
Contributor

There are two cases that could probably be patched and prevented:

  1. Try to create 0 or fewer processes of a new type
    e.g. app.processes.add('web', 0)
  2. Try to scale to a number of dynos that's not an integer (whether that process type is currently running or not)
    e.g. app.processes['web'].scale('aaa')

The Heroku Toolbelt prevents these from happening, so I'm guessing you guys like to prevent this behaviour :) However, both of these calls currently throw a KeyError:

File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 55, in add
    return self[0].new(*args, **kwargs)
  File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/models.py", line 515, in new
    return self.app.processes[type]
  File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 106, in __getitem__
    raise why
KeyError: 'web'

Now we could add code inside Process.scale() and Process.new() to check for non-integers and quantities < 1. However it seems like The Heroku Way in this module is to try taking actions and raise errors if they don't work? Also on the HEAD branch if we try to scale a process to a number of dynos that's < 1 we get this response from the server:

File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/structures.py", line 46, in add
return self[0].new(_args, *_kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/models.py", line 505, in new
data={'type': type, 'qty': quantity}
File "/app/.heroku/venv/lib/python2.7/site-packages/heroku/api.py", line 103,in _http_resource
raise http_error
requests.exceptions.HTTPError: 422 Client Error: {"error":"Cannot scale to fewer than 0 dynos per process type."}

So perhaps you'd prefer to write server code to deal with these situations instead, which will then get caught by the calls to r.raise_for_status() in both Process.new() and Process.scale()

Let me know! :)

@edmorley
Copy link
Member

This project has been deprecated for some time, and is now being sunset.

We recommend that you use the maintained https://github.com/martyzz1/heroku3.py instead.

@edmorley edmorley closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants