|
45 | 45 | from servicelib.rabbitmq import RPCRouter |
46 | 46 |
|
47 | 47 | from . import _functions_repository |
48 | | -from ._functions_exceptions import FunctionGroupAccessRightsNotFoundError |
| 48 | +from ._functions_exceptions import ( |
| 49 | + FunctionGroupAccessRightsNotFoundError, |
| 50 | + IncompatiblePatchModelError, |
| 51 | +) |
49 | 52 |
|
50 | 53 | router = RPCRouter() |
51 | 54 |
|
@@ -110,6 +113,13 @@ async def patch_registered_function_job( |
110 | 113 | product_name=product_name, |
111 | 114 | function_job_id=function_job_uuid, |
112 | 115 | ) |
| 116 | + if job.function_class != registered_function_job_patch.function_class: |
| 117 | + raise IncompatiblePatchModelError( |
| 118 | + function_id=job.function_uuid, |
| 119 | + product_name=product_name, |
| 120 | + ) |
| 121 | + |
| 122 | + patched_job = _patch_functionjob(job, registered_function_job_patch) |
113 | 123 |
|
114 | 124 | await _functions_repository.patch_function_job( |
115 | 125 | app=app, |
@@ -781,3 +791,62 @@ def _decode_functionjob( |
781 | 791 | raise UnsupportedFunctionJobClassError( |
782 | 792 | function_job_class=functionjob_db.function_class |
783 | 793 | ) |
| 794 | + |
| 795 | + |
| 796 | +def _patch_functionjob( |
| 797 | + function_job_db: RegisteredFunctionJobDB, |
| 798 | + patch: RegisteredFunctionJobPatch, |
| 799 | +) -> RegisteredFunctionJobDB: |
| 800 | + if function_job_db.function_class == FunctionClass.PROJECT: |
| 801 | + assert patch.function_class == FunctionClass.PROJECT # nosec |
| 802 | + return RegisteredFunctionJobDB( |
| 803 | + function_class=FunctionClass.PROJECT, |
| 804 | + function_uuid=function_job_db.function_uuid, |
| 805 | + title=patch.title or function_job_db.title, |
| 806 | + uuid=function_job_db.uuid, |
| 807 | + description=patch.description or function_job_db.description, |
| 808 | + inputs=function_job_db.inputs, |
| 809 | + outputs=function_job_db.outputs, |
| 810 | + created=function_job_db.created, |
| 811 | + class_specific_data=FunctionClassSpecificData( |
| 812 | + project_job_id=patch.project_job_id |
| 813 | + or function_job_db.class_specific_data.get("project_job_id"), |
| 814 | + job_creation_task_id=patch.job_creation_task_id |
| 815 | + or function_job_db.class_specific_data.get("job_creation_task_id"), |
| 816 | + ), |
| 817 | + ) |
| 818 | + elif function_job_db.function_class == FunctionClass.SOLVER: |
| 819 | + assert patch.function_class == FunctionClass.SOLVER # nosec |
| 820 | + return RegisteredFunctionJobDB( |
| 821 | + function_class=FunctionClass.SOLVER, |
| 822 | + function_uuid=function_job_db.function_uuid, |
| 823 | + title=patch.title or function_job_db.title, |
| 824 | + uuid=function_job_db.uuid, |
| 825 | + description=patch.description or function_job_db.description, |
| 826 | + inputs=function_job_db.inputs, |
| 827 | + outputs=function_job_db.outputs, |
| 828 | + created=function_job_db.created, |
| 829 | + class_specific_data=FunctionClassSpecificData( |
| 830 | + solver_job_id=patch.solver_job_id |
| 831 | + or function_job_db.class_specific_data.get("solver_job_id"), |
| 832 | + job_creation_task_id=patch.job_creation_task_id |
| 833 | + or function_job_db.class_specific_data.get("job_creation_task_id"), |
| 834 | + ), |
| 835 | + ) |
| 836 | + elif function_job_db.function_class == FunctionClass.PYTHON_CODE: |
| 837 | + assert patch.function_class == FunctionClass.PYTHON_CODE # nosec |
| 838 | + return RegisteredFunctionJobDB( |
| 839 | + function_class=FunctionClass.PYTHON_CODE, |
| 840 | + function_uuid=function_job_db.function_uuid, |
| 841 | + title=patch.title or function_job_db.title, |
| 842 | + uuid=function_job_db.uuid, |
| 843 | + description=patch.description or function_job_db.description, |
| 844 | + inputs=function_job_db.inputs, |
| 845 | + outputs=function_job_db.outputs, |
| 846 | + created=function_job_db.created, |
| 847 | + class_specific_data=function_job_db.class_specific_data, |
| 848 | + ) |
| 849 | + else: |
| 850 | + raise UnsupportedFunctionJobClassError( |
| 851 | + function_job_class=function_job_db.function_class |
| 852 | + ) |
0 commit comments