(self, *args, **kwargs)
| 526 | return self.get(pack=value, raise_exception=True) |
| 527 | |
| 528 | def get(self, *args, **kwargs): |
| 529 | exclude_fields = kwargs.pop("exclude_fields", None) |
| 530 | raise_exception = kwargs.pop("raise_exception", False) |
| 531 | only_fields = kwargs.pop("only_fields", None) |
| 532 | |
| 533 | args = self._process_arg_filters(args) |
| 534 | |
| 535 | instances = self.model.objects(*args, **kwargs) |
| 536 | |
| 537 | if exclude_fields: |
| 538 | instances = instances.exclude(*exclude_fields) |
| 539 | |
| 540 | if only_fields: |
| 541 | try: |
| 542 | instances = instances.only(*only_fields) |
| 543 | except (mongoengine.errors.LookUpError, AttributeError) as e: |
| 544 | msg = ( |
| 545 | "Invalid or unsupported include attribute specified: %s" |
| 546 | % six.text_type(e) |
| 547 | ) |
| 548 | raise ValueError(msg) |
| 549 | |
| 550 | instance = instances[0] if instances else None |
| 551 | log_query_and_profile_data_for_queryset(queryset=instances) |
| 552 | |
| 553 | if not instance and raise_exception: |
| 554 | msg = "Unable to find the %s instance. %s" % (self.model.__name__, kwargs) |
| 555 | raise db_exc.StackStormDBObjectNotFoundError(msg) |
| 556 | |
| 557 | return instance |
| 558 | |
| 559 | def get_all(self, *args, **kwargs): |
| 560 | return self.query(*args, **kwargs) |
no test coverage detected