Skip to content

Commit 9a23c8d

Browse files
authored
230 allow empty subscriptions (#231)
* fix(subscriptions): allow showing empty subscriptions * fix(subscriptions): add error handling for validation
1 parent cda0272 commit 9a23c8d

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

app/Entirety/subscriptions/views/list.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,21 @@ def get_queryset(self):
5353
sub.description = sub_cb.description
5454
sub.status = sub_cb.status
5555
sub.project = self.project
56-
if sub_cb.subject.entities[0].id:
57-
sub.entity_id = sub_cb.subject.entities[0].id
58-
if sub_cb.subject.entities[0].idPattern:
59-
sub.entity_id_pattern = sub_cb.subject.entities[0].idPattern.pattern
60-
if sub_cb.subject.entities[0].type:
61-
sub.entity_type = sub_cb.subject.entities[0].type
62-
if sub_cb.subject.entities[0].typePattern:
63-
sub.entity_type_pattern = sub_cb.subject.entities[
64-
0
65-
].typePattern.pattern
56+
if not sub_cb.subject.entities:
57+
pass # add nothing if no entities
58+
else:
59+
if sub_cb.subject.entities[0].id:
60+
sub.entity_id = sub_cb.subject.entities[0].id
61+
if sub_cb.subject.entities[0].idPattern:
62+
sub.entity_id_pattern = sub_cb.subject.entities[
63+
0
64+
].idPattern.pattern
65+
if sub_cb.subject.entities[0].type:
66+
sub.entity_type = sub_cb.subject.entities[0].type
67+
if sub_cb.subject.entities[0].typePattern:
68+
sub.entity_type_pattern = sub_cb.subject.entities[
69+
0
70+
].typePattern.pattern
6671
# get url
6772
url = self.get_notification_url(sub_cb)
6873
sub.notification_endpoint = url

app/Entirety/subscriptions/views/update.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ def post(self, request, *args, **kwargs):
213213
id=(
214214
entity_form.cleaned_data["entity_id"]
215215
if entity_selector == "id"
216+
and entity_form.cleaned_data["entity_id"]
216217
else None
217218
),
218219
idPattern=(
219220
utils.safe_compile(
220221
entity_form.cleaned_data["entity_id"]
221222
)
222223
if entity_selector == "id_pattern"
224+
and entity_form.cleaned_data["entity_id"]
223225
else None
224226
),
225227
type=(
@@ -233,6 +235,7 @@ def post(self, request, *args, **kwargs):
233235
entity_form.cleaned_data["entity_type"]
234236
)
235237
if type_selector == "type_pattern"
238+
and entity_form.cleaned_data["entity_type"]
236239
else None
237240
),
238241
)
@@ -251,6 +254,21 @@ def post(self, request, *args, **kwargs):
251254
)
252255
messages.error(request, e)
253256
return self.form_invalid(form)
257+
except ValueError as e:
258+
logger.error(
259+
str(
260+
self.request.user.first_name
261+
if self.request.user.first_name
262+
else self.request.user.username
263+
)
264+
+ " tried updating the subscription with name "
265+
+ self.object.uuid
266+
+ " but failed "
267+
f" in project {self.project.name}"
268+
)
269+
messages.error(request, e)
270+
return self.form_invalid(form)
271+
254272
with ContextBrokerClient(
255273
url=settings.CB_URL,
256274
fiware_header=FiwareHeader(

0 commit comments

Comments
 (0)