11from __future__ import annotations
22
3+ from copy import deepcopy
34from typing import (
45 Any ,
56 ClassVar ,
7+ Iterable ,
68 Optional ,
79 Type ,
810 final ,
1315 RAISE ,
1416 Schema ,
1517 fields ,
18+ post_dump ,
1619 post_load ,
1720 pre_load ,
1821)
2427)
2528from dl_constants .enums import (
2629 CreateMode ,
30+ ExportMode ,
2731 FileProcessingStatus ,
2832 ImportMode ,
2933 UserDataType ,
@@ -47,14 +51,25 @@ class Meta:
4751
4852 target : Type [BaseFileS3Connection .FileDataSource ]
4953
50- @post_load (pass_many = False )
51- def post_load (self , data : dict [str , Any ], ** kwargs : Any ) -> BaseFileS3Connection .FileDataSource :
52- return self .Meta .target (** data )
53-
5454 @property
5555 def operations_mode (self ) -> Optional [CreateMode | ImportMode ]:
5656 return self .context .get (self .CTX_KEY_OPERATIONS_MODE )
5757
58+ @staticmethod
59+ def get_field_extra (f : fields .Field ) -> Optional [FieldExtra ]:
60+ return f .metadata .get ("bi_extra" , None )
61+
62+ @classmethod
63+ def all_fields_dict (cls ) -> dict [str , fields .Field ]:
64+ return cls ._declared_fields
65+
66+ @classmethod
67+ def fieldnames_with_extra_export_fake_info (cls ) -> Iterable [str ]:
68+ for field_name , field in cls .all_fields_dict ().items ():
69+ extra = cls .get_field_extra (field )
70+ if extra is not None and extra .export_fake is True :
71+ yield field_name
72+
5873 @final
5974 def delete_unknown_fields (self , data : dict [str , Any ]) -> dict [str , Any ]:
6075 cleaned_data = {}
@@ -64,14 +79,27 @@ def delete_unknown_fields(self, data: dict[str, Any]) -> dict[str, Any]:
6479
6580 return cleaned_data
6681
82+ @post_load (pass_many = False )
83+ def post_load (self , data : dict [str , Any ], ** kwargs : Any ) -> BaseFileS3Connection .FileDataSource :
84+ return self .Meta .target (** data )
85+
6786 @pre_load (pass_many = False )
6887 def pre_load (self , data : dict [str , Any ], ** _ : Any ) -> dict [str , Any ]:
6988 if isinstance (self .operations_mode , ImportMode ):
7089 return self .delete_unknown_fields (data )
7190 return data
7291
92+ @post_dump (pass_many = False )
93+ def post_dump (self , data : dict [str , Any ], ** _ : Any ) -> dict [str , Any ]:
94+ if isinstance (self .operations_mode , ExportMode ):
95+ data = deepcopy (data )
96+ for secret_field in self .fieldnames_with_extra_export_fake_info ():
97+ data [secret_field ] = "******"
98+ return self .delete_unknown_fields (data )
99+ return data
100+
73101 id = fields .String ()
74- file_id = fields .String (load_default = None )
102+ file_id = fields .String (load_default = None , bi_extra = FieldExtra ( export_fake = True ) )
75103 title = fields .String (bi_extra = FieldExtra (editable = True ))
76104 status = fields .Enum (FileProcessingStatus , dump_only = True )
77105 raw_schema = fields .Nested (
0 commit comments