<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_by_id(self, query):
 """Apply the primary key filter to query to filter the results for a specific instance by id. The filter applied by the this method by default can be controlled using the url_id_param :param query: SQLAlchemy Query :returns: A SQLAlchemy Query object """

        if self.model is None:
            raise ArrestedException('DBObjectMixin requires a model to be set.')

        idfield = getattr(self.model, self.model_id_param, None)
        if not idfield:
            raise ArrestedException('DBObjectMixin could not find a valid Model.id.')

        return query.filter(idfield == self.kwargs[self.url_id_param])