{"record":{"id":"80306776e36b335e","repo":"feder-cr/Jobs_Applier_AI_Agent_AIHawk","slug":"attribute-error-in-work-preferences-processing","errorCode":null,"errorMessage":"Attribute error in work_preferences processing.","messagePattern":"Attribute error in work_preferences processing\\.","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/resume_schemas/job_application_profile.py","lineNumber":131,"sourceCode":"            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\n        except TypeError as e:\n            logger.error(f\"Error in availability data: {e}\")\n            raise TypeError(f\"Error in availability data: {e}\") from e\n        except AttributeError as e:\n            logger.error(f\"Attribute error in availability processing: {e}\")\n            raise AttributeError(\"Attribute error in availability processing.\") from e","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/feder-cr/Jobs_Applier_AI_Agent_AIHawk/blob/79155b52faccfbd19b834680af285eac70dd2df4/src/resume_schemas/job_application_profile.py#L113-L149","documentation":"AttributeError wrapper from the work_preferences try block: an attribute access on a wrongly-typed value (None/str) inside WorkPreferences construction is caught and re-raised as this generic message. As with the sibling handlers, the specifics live in the chained exception and the logger.error output, not the static message.","triggerScenarios":"Nested work_preferences fields (e.g. a shift or location preference) that are None/scalar while the code calls dict methods like .get/.items on them.","commonSituations":"Sparse YAML where optional preference subsections are null; data from external scrapers with inconsistent types; refactors changing nested field structure.","solutions":["Read e.__cause__ or the logged line to locate the failing attribute.","Type-check and normalize nested work_preferences values (None → {}) before building the profile.","Add defaults in WorkPreferences' constructor for optional nested objects."],"exampleFix":"# before\nwp = data['work_preferences']  # {'desired_locations': None}\nself.work_preferences = WorkPreferences(**wp)\n\n# after\nwp = {k: (v if isinstance(v, (dict, list, bool, int, str)) else {}) for k, v in (data.get('work_preferences') or {}).items()}\nself.work_preferences = WorkPreferences(**wp)","handlingStrategy":"validation","validationCode":"wp = data.get('work_preferences') or {}\nwp = {k: (v if v is not None else {}) for k, v in wp.items()}","typeGuard":"def work_preferences_fields_valid(wp) -> bool:\n    return isinstance(wp, dict) and all(v is None or isinstance(v, (dict, list, str, bool, int)) for v in wp.values())","tryCatchPattern":"try:\n    profile = JobApplicationProfile(**data)\nexcept AttributeError as e:\n    if 'work_preferences' in str(e):\n        log.error('attr cause: %r', e.__cause__)","preventionTips":["Fill None nested fields with defaults before constructing","Maintain consistent producers of nested preference data"],"tags":["python","attributeerror","null-handling","work-preferences"],"backgroundTag":"schema-validation-failed","analyzedSha":"79155b52faccfbd19b834680af285eac70dd2df4","analyzedAt":"2026-08-28T14:10:26.659Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}