mirror of https://github.com/jumpserver/jumpserver
Merge pull request #9366 from jumpserver/pr@dev@fix_no_db_name_mongodb_task_err
fix: mongodb无指定数据库时,一些自动化任务会失败pull/9374/head
commit
685b99e04d
|
@ -1,3 +1,6 @@
|
|||
from rest_framework.serializers import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from assets.models import Database
|
||||
from .common import AssetSerializer
|
||||
from ..gateway import GatewayWithAccountSecretSerializer
|
||||
|
@ -14,6 +17,13 @@ class DatabaseSerializer(AssetSerializer):
|
|||
]
|
||||
fields = AssetSerializer.Meta.fields + extra_fields
|
||||
|
||||
def validate(self, attrs):
|
||||
platform = attrs.get('platform')
|
||||
if platform and getattr(platform, 'type') == 'mongodb' \
|
||||
and not attrs.get('db_name'):
|
||||
raise ValidationError({'db_name': _('This field is required.')})
|
||||
return attrs
|
||||
|
||||
|
||||
class DatabaseWithGatewaySerializer(DatabaseSerializer):
|
||||
gateway = GatewayWithAccountSecretSerializer()
|
||||
|
|
Loading…
Reference in New Issue