Issue #2775
Updated by bizhang over 7 years ago
h2. Problem: Currently Worker name is being used as the natural key, this is good because worker lookup urls are informative and expressive. Worker name currently is {service_name}@{host}. This is also good and makes a lot of sense. The issue is that "reserved":https://tools.ietf.org/html/rfc3986#section-2.2 characters should not be allowed in url path variables.. Django urlquotes the generated url [0] however since @ is a reserved character that could show up in urls, django ignores it. Passing in a prequoted worker name would not work since django would urlquote the <code>%40</code> h2. Potential Solutions: 1.) Create A potential solution could be to create a new drf field and overwrite the get_url[1] function to take the full url django returns, and urlquote only the last path variable. To me this seems like a hack, but it would theoretically work. This allows us Alternatively it might be better to keep @ the worker service_name and the worker host as two separate fields in the delimiting worker model, Worker name would be <code>'@'.join(service, host)</code> and lookup_value would be <code>'%40'.join(service, host)</code>. There would be some work involved in not letting Django urlquote the % in %40, so it might be better to use some other join character 2.) Use a different delimiter. Some proposed ones are <code>.~-_</code> 3.) Structure for the worker url like '-'. Or we can structure the lookup url path to nest host and service name take use two path variables <code>/workers/{host}/{service}/</code> The issue with this approach is spelled out in https://pulp.plan.io/issues/2775?pn=1#note-9 4.) The easiest solution would be to, of course, switch to using UUID for the worker lookup_field. We But we would lose the expressiveness of using the natural key, but can keep the @ in the worker name key. Or there might be some other solution that I'm not seeing [0] https://github.com/django/django/blob/stable/1.8.x/django/utils/encoding.py#L210 [1] https://github.com/encode/django-rest-framework/blob/ee1a9fcef659d0a5885712575562acb71a502f21/rest_framework/relations.py#L300