1212from typing import Any , Dict , List , Optional , Tuple , Union
1313
1414import requests
15- from pydantic import BaseModel , Field
15+ from pydantic import BaseModel , ConfigDict , Field
1616from workflows .transport import pika_transport
1717
1818import zocalo .configuration
@@ -404,9 +404,7 @@ class ExchangeSpec(BaseModel):
404404 vhost : str = Field (
405405 ..., description = "Virtual host name with non-ASCII characters escaped as in C."
406406 )
407-
408- class Config :
409- use_enum_values = True
407+ model_config = ConfigDict (use_enum_values = True )
410408
411409
412410class ExchangeInfo (ExchangeSpec ):
@@ -456,11 +454,9 @@ class PolicySpec(BaseModel):
456454 alias = "apply-to" ,
457455 description = "Which types of object this policy should apply to." ,
458456 )
459-
460- class Config :
461- use_enum_values = True
462- validate_all = True
463- allow_population_by_field_name = True
457+ model_config = ConfigDict (
458+ use_enum_values = True , validate_default = True , populate_by_name = True
459+ )
464460
465461
466462class QueueState (str , enum .Enum ):
@@ -617,9 +613,7 @@ class UserSpec(BaseModel):
617613 password_hash : str = Field (..., description = "Hash of the user password." )
618614 hashing_algorithm : HashingAlgorithm
619615 tags : List [str ]
620-
621- class Config :
622- use_enum_values = True
616+ model_config = ConfigDict (use_enum_values = True )
623617
624618
625619def http_api_request (
@@ -778,7 +772,7 @@ def binding_declare(self, binding: BindingSpec):
778772 endpoint = f"bindings/{ binding .vhost } /e/{ binding .source } /{ binding .destination_type .value } /{ binding .destination } "
779773 response = self .post (
780774 endpoint ,
781- json = binding .dict (
775+ json = binding .model_dump (
782776 exclude_defaults = True ,
783777 exclude = {"vhost" , "source" , "destination" , "destination_type" },
784778 ),
@@ -854,7 +848,7 @@ def exchange_declare(self, exchange: ExchangeSpec):
854848 endpoint = f"exchanges/{ exchange .vhost } /{ exchange .name } /"
855849 response = self .put (
856850 endpoint ,
857- json = exchange .dict (exclude_defaults = True , exclude = {"name" , "vhost" }),
851+ json = exchange .model_dump (exclude_defaults = True , exclude = {"name" , "vhost" }),
858852 )
859853 response .raise_for_status ()
860854
@@ -879,7 +873,7 @@ def set_policy(self, policy: PolicySpec):
879873 endpoint = f"policies/{ policy .vhost } /{ policy .name } /"
880874 response = self .put (
881875 endpoint ,
882- json = policy .dict (
876+ json = policy .model_dump (
883877 exclude_defaults = True , exclude = {"name" , "vhost" }, by_alias = True
884878 ),
885879 )
@@ -908,7 +902,8 @@ def queues(
908902 def queue_declare (self , queue : QueueSpec ):
909903 endpoint = f"queues/{ queue .vhost } /{ queue .name } "
910904 response = self .put (
911- endpoint , json = queue .dict (exclude_defaults = True , exclude = {"name" , "vhost" })
905+ endpoint ,
906+ json = queue .model_dump (exclude_defaults = True , exclude = {"name" , "vhost" }),
912907 )
913908 response .raise_for_status ()
914909
@@ -948,7 +943,9 @@ def permissions(
948943
949944 def set_permissions (self , permission : PermissionSpec ):
950945 endpoint = f"permissions/{ permission .vhost } /{ permission .user } /"
951- submission = permission .dict (exclude_defaults = True , exclude = {"vhost" , "user" })
946+ submission = permission .model_dump (
947+ exclude_defaults = True , exclude = {"vhost" , "user" }
948+ )
952949 response = self .put (endpoint , json = submission )
953950 response .raise_for_status ()
954951
@@ -959,7 +956,7 @@ def clear_permissions(self, vhost: str, user: str):
959956
960957 def user_put (self , user : UserSpec ):
961958 endpoint = f"users/{ user .name } /"
962- submission = user .dict (exclude_defaults = True , exclude = {"name" })
959+ submission = user .model_dump (exclude_defaults = True , exclude = {"name" })
963960 submission ["tags" ] = "," .join (submission ["tags" ])
964961 response = self .put (endpoint , json = submission )
965962 response .raise_for_status ()
@@ -982,7 +979,8 @@ def vhost(self, name: str) -> VHostSpec:
982979 def add_vhost (self , vhost : VHostSpec ):
983980 endpoint = f"vhosts/{ vhost .name } /"
984981 response = self .put (
985- endpoint , json = vhost .dict (exclude_defaults = True , exclude = {"name" , "vhost" })
982+ endpoint ,
983+ json = vhost .model_dump (exclude_defaults = True , exclude = {"name" , "vhost" }),
986984 )
987985 response .raise_for_status ()
988986
0 commit comments