{"record":{"id":"934d7d807154e0e2","repo":"feder-cr/Jobs_Applier_AI_Agent_AIHawk","slug":"required-field-e-is-missing-in-work-preferences","errorCode":null,"errorMessage":"Required field {e} is missing in work_preferences data.","messagePattern":"Required field (.+?) is missing in work_preferences data\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/resume_schemas/job_application_profile.py","lineNumber":125,"sourceCode":"            raise KeyError(f\"Required field {e} is missing in legal_authorization data.\") from e\n        except TypeError as e:\n            logger.error(f\"Error in legal_authorization data: {e}\")\n            raise TypeError(f\"Error in legal_authorization data: {e}\") from e\n        except AttributeError as e:\n            logger.error(f\"Attribute error in legal_authorization processing: {e}\")\n            raise AttributeError(\"Attribute error in legal_authorization processing.\") from e\n        except Exception as e:\n            logger.error(f\"An unexpected error occurred while processing legal_authorization: {e}\")\n            raise RuntimeError(\"An unexpected error occurred while processing legal_authorization.\") from e\n\n        # Process work_preferences\n        try:\n            logger.debug(\"Processing work_preferences\")\n            self.work_preferences = WorkPreferences(**data['work_preferences'])\n            logger.debug(f\"Work_preferences processed: {self.work_preferences}\")\n        except KeyError as e:\n            logger.error(f\"Required field {e} is missing in work_preferences data.\")\n            raise KeyError(f\"Required field {e} is missing in work_preferences data.\") from e\n        except TypeError as e:\n            logger.error(f\"Error in work_preferences data: {e}\")\n            raise TypeError(f\"Error in work_preferences data: {e}\") from e\n        except AttributeError as e:\n            logger.error(f\"Attribute error in work_preferences processing: {e}\")\n            raise AttributeError(\"Attribute error in work_preferences processing.\") from e\n        except Exception as e:\n            logger.error(f\"An unexpected error occurred while processing work_preferences: {e}\")\n            raise RuntimeError(\"An unexpected error occurred while processing work_preferences.\") from e\n\n        # Process availability\n        try:\n            logger.debug(\"Processing availability\")\n            self.availability = Availability(**data['availability'])\n            logger.debug(f\"Availability processed: {self.availability}\")\n        except KeyError as e:\n            logger.error(f\"Required field {e} is missing in availability data.\")\n            raise KeyError(f\"Required field {e} is missing in availability data.\") from e","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/feder-cr/Jobs_Applier_AI_Agent_AIHawk/blob/79155b52faccfbd19b834680af285eac70dd2df4/src/resume_schemas/job_application_profile.py#L107-L143","documentation":"KeyError raised from the work_preferences block of JobApplicationProfile.__init__: either 'work_preferences' itself is absent from data (dict indexing data['work_preferences']), or the WorkPreferences constructor is missing a required key and its own KeyError propagates here. The missing key name appears in the interpolated message.","triggerScenarios":"JobApplicationProfile(**data) called with a resume dict lacking 'work_preferences', or with a work_preferences mapping missing a field WorkProfiles requires (e.g. 'remote').","commonSituations":"Resume files that omit optional-feeling sections like work preferences; data pipelines trimming empty dicts; schema evolution adding new required keys.","solutions":["Supply the missing key named in the message, at the top level or inside work_preferences.","Default the section if optional: data.setdefault('work_preferences', {}) before construction.","Check WorkPreferences.__init__ for required fields and pre-fill them from the source data."],"exampleFix":"# before\nself.work_preferences = WorkPreferences(**data['work_preferences'])\n\n# after\nwp = data.get('work_preferences') or {}\nself.work_preferences = WorkPreferences(**wp)","handlingStrategy":"validation","validationCode":"data.setdefault('work_preferences', {})","typeGuard":"def has_work_preferences(data: dict) -> bool:\n    return isinstance(data.get('work_preferences'), dict)","tryCatchPattern":"try:\n    profile = JobApplicationProfile(**data)\nexcept KeyError as e:\n    if 'work_preferences' in str(e):\n        data.setdefault('work_preferences', {})\n        profile = JobApplicationProfile(**data)","preventionTips":["Default optional sections to empty dicts before construction","Validate top-level keys against the schema at load time"],"tags":["python","keyerror","missing-field","work-preferences"],"backgroundTag":"missing-required-field","analyzedSha":"79155b52faccfbd19b834680af285eac70dd2df4","analyzedAt":"2026-08-28T14:10:26.659Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}