getattr
PTC-W0034getattr
is missing a default value18 self.getter = getter
19
20 def serialize(self, attr, obj, accessor=None):
21 return super().serialize(getattr(self, 'getter') or attr, obj, accessor)22
23
24class TrimmedEmail(fields.Email):
getattr
is missing a default value435 if view_kwargs.get('group_id') and 'GET' in request.method:
436 group = safe_query(Group, 'id', view_kwargs.get('group_id'), 'group_id')
437 query_ = self.session.query(Event).filter(
438 getattr(Event, 'group_id') == view_kwargs['group_id']439 )
440
441 return query_
getattr
is missing a default value429 if not has_access('is_coorganizer', event_id=event_id):
430 raise ForbiddenError({'source': ''}, 'Coorganizer access is required')
431 query_ = self.session.query(Event).filter(
432 getattr(Event, 'discount_code_id') == view_kwargs['discount_code_id']433 )
434
435 if view_kwargs.get('group_id') and 'GET' in request.method:
getattr
is missing a default value421
422 if view_kwargs.get('event_sub_topic_id') and 'GET' in request.method:
423 query_ = self.session.query(Event).filter(
424 getattr(Event, 'event_sub_topic_id') == view_kwargs['event_sub_topic_id']425 )
426
427 if view_kwargs.get('discount_code_id') and 'GET' in request.method:
getattr
is missing a default value416
417 if view_kwargs.get('event_topic_id') and 'GET' in request.method:
418 query_ = self.session.query(Event).filter(
419 getattr(Event, 'event_topic_id') == view_kwargs['event_topic_id']420 )
421
422 if view_kwargs.get('event_sub_topic_id') and 'GET' in request.method:
getattr
is being used to check if an attribute exists, without specifying a default value.
Missing a default to getattr
will cause an AttributeError
to be raised for non-existent properties, which is the same as when a non-existent property is accessed directly.
It is recommended to either provide a default value to be returned by getattr
if the attribute is not found, or access the attribute directly as there is no additional safety in using getattr
if the attribute name is known ahead of time.