graceful handling of common issues - ppa name case handling

Bug #1989081 reported by Christian Ehrhardt 
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ppa-dev-tools
Fix Released
Undecided
Bryce Harrington

Bug Description

PPA names do - by design - not allow upper case characters.
Therefore we should auto-lowercase them for the user.

And thereby avoid massive backtraces and issue like:

1. creation

$ ppa create lp-1975764-DPDK-MRE-Sept-2022
Traceback (most recent call last):
  File "/usr/local/bin/ppa", line 4, in <module>
    __import__('pkg_resources').run_script('ppa-dev-tools==0.1.0', 'ppa')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1453, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 533, in <module>
    sys.exit(main(args))
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 522, in main
    return func(lp, config)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 238, in command_create
    ppa = ppa_group.create(ppa_name, ppa_description=description)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa_group.py", line 103, in create
    raise e
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa_group.py", line 94, in create
    results = self.team.createPPA(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 592, in __call__
    response, content = self.root._browser._request(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 429, in _request
    raise error
lazr.restfulclient.errors.BadRequest: HTTP Error 400: Bad Request
Response headers:
---
-content-encoding: gzip
connection: close
content-length: 271
content-security-policy: frame-ancestors 'self';
content-type: text/plain;charset=utf-8
date: Thu, 08 Sep 2022 08:27:14 GMT
server: gunicorn/19.8.1
status: 400
strict-transport-security: max-age=15552000
vary: Accept,Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-launchpad-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-lazr-notifications: []
x-powered-by: Zope (www.zope.org), Python (www.python.org)
x-request-id: 9a928cf4-3744-4445-991f-c6a2be8d430b
x-vcs-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-xss-protection: 1; mode=block
---
Response body:
---
b"name: \nInvalid name 'lp-1975764-DPDK-MRE-Sept-2022'. Names must be at least two characters long\nand start with a letter or number. All letters must be lower-case.\nThe characters <samp>+</samp>, <samp>-</samp> and <samp>.</samp>\nare also allowed after the first character."
---

2. trying to access with accidential upper case

$ ppa wait ppa:paelzer/lp-1975764-DPDK-mre-sept-2022
Traceback (most recent call last):
  File "/usr/local/bin/ppa", line 4, in <module>
    __import__('pkg_resources').run_script('ppa-dev-tools==0.1.0', 'ppa')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1453, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 533, in <module>
    sys.exit(main(args))
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 522, in main
    return func(lp, config)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 437, in command_wait
    if not ppa.has_packages():
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa.py", line 222, in has_packages
    return list(self.archive.getPublishedSources()) != []
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa.py", line 96, in archive
    return owner.getPPAByName(name=self.ppa_name)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 592, in __call__
    response, content = self.root._browser._request(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 429, in _request
    raise error
lazr.restfulclient.errors.BadRequest: HTTP Error 400: Bad Request
Response headers:
---
-content-encoding: gzip
connection: close
content-length: 271
content-security-policy: frame-ancestors 'self';
content-type: text/plain;charset=utf-8
date: Thu, 08 Sep 2022 08:40:45 GMT
server: gunicorn/19.8.1
status: 400
strict-transport-security: max-age=15552000
vary: Accept,Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-launchpad-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-lazr-notifications: []
x-powered-by: Zope (www.zope.org), Python (www.python.org)
x-request-id: a434c856-04b9-4a3a-9e36-c53ec88bd36c
x-vcs-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-xss-protection: 1; mode=block
---
Response body:
---
b"name: \nInvalid name 'lp-1975764-DPDK-mre-sept-2022'. Names must be at least two characters long\nand start with a letter or number. All letters must be lower-case.\nThe characters <samp>+</samp>, <samp>-</samp> and <samp>.</samp>\nare also allowed after the first character."
---

Up for discussion if we want to warn the user or auto-lowercase it.
Since by design it can only ever be lower case, I'm leaning towards converting to lower case and mentioning that in --help.

Related branches

Revision history for this message
Bryce Harrington (bryce) wrote :

Yeah this should be detected and reported better to users.

For auto-correction I'm a bit concerned that this may have some surprise if they then try to use that invalid name, especially with scripting, e.g.:

  my_ppa="lp-1975764-DPDK-mre-sept-2022"
  ppa create "${my_ppa}" || exit 1
  dput "${my_ppa}" "${changes_file}"

In this case $my_ppa would get auto-corrected but then the script would fail on the dput which could be bad.

The ppa name format is strict on characters that can be used, as well as length, and I don't think we'd want to autocorrect those, so I suspect it'd be most consistent to also error on capitalized letters.

Bryce Harrington (bryce)
Changed in ppa-dev-tools:
assignee: nobody → Bryce Harrington (bryce)
status: New → In Progress
Bryce Harrington (bryce)
Changed in ppa-dev-tools:
status: In Progress → Fix Committed
Revision history for this message
Bryce Harrington (bryce) wrote :

[This fix was included in the 0.3 release]

Changed in ppa-dev-tools:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.