{"record":{"id":"e55fd1cde30e6cd9","repo":"squidfunk/mkdocs-material","slug":"expected-type-date-or-datetime-but-received","errorCode":null,"errorMessage":"Expected type: {date} or {datetime} but received: {type(value[key])}","messagePattern":"Expected type: (.+?) or (.+?) but received: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"src/plugins/blog/structure/options.py","lineNumber":92,"sourceCode":"                # Set timezone to UTC if not set\n                if value.tzinfo is None:\n                    config[key_name][key] = value.replace(tzinfo=timezone.utc)\n                continue;\n\n\n            # Handle date - we set 00:00:00 as the default time, if the author\n            # only supplied a date, and convert it to datetime in UTC\n            if isinstance(value, date):\n                config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)\n\n        # Initialize date dictionary\n        config[key_name] = DateDict(config[key_name])\n\n    # Ensure each date value is of type datetime\n    def run_validation(self, value: DateDict):\n        for key in value:\n            if not isinstance(value[key], datetime):\n                raise ValidationError(\n                    f\"Expected type: {date} or {datetime} \"\n                    f\"but received: {type(value[key])}\"\n                )\n\n        # Ensure presence of `date.created`\n        if not value.created:\n            raise ValidationError(\n                \"Expected 'created' date when using dictionary syntax\"\n            )\n\n        # Return date dictionary\n        return value\n\n# -----------------------------------------------------------------------------\n\n# Post links option\nclass PostLinks(BaseConfigOption[Navigation]):\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/squidfunk/mkdocs-material/blob/e2136532f40aed98af1f6497c0cc6a3cff9f759b/src/plugins/blog/structure/options.py#L74-L110","documentation":"The blog plugin's date option accepts either a single date/datetime or a dictionary of date keys (created, updated, etc.). `run_validation` iterates the DateDict and raises this ValidationError if any value is not a `datetime` instance.","triggerScenarios":"In a post's front-matter, a key inside the date dictionary (e.g. `date: {created: 2024-01-15, updated: ...}`) is set to a string, int, or other non-date value, so after parsing it is not a `datetime`.","commonSituations":"Writing `date: {created: 'yesterday'}` or an unparseable/timestamp-as-string value; YAML keeping the value as a string because the format is not a recognized date; passing a plain string like `2024-01-15` in quotes where the loader doesn't coerce it.","solutions":["Use ISO 8601 date values in the date dictionary, e.g. `date: {created: 2024-01-15}`","Unquote date strings so YAML parses them as dates","Remove non-date keys from the date dictionary"],"exampleFix":"# before\n---\ndate:\n  created: '2024/01/15'\n  updated: soon\n---\n\n// after\n---\ndate:\n  created: 2024-01-15\n  updated: 2024-02-01\n---","handlingStrategy":"type-guard","validationCode":"import yaml, datetime\nfor p in Path('docs/posts').rglob('*.md'):\n    meta = yaml.safe_load(p.read_text().split('---')[1])\n    d = meta.get('date')\n    if isinstance(d, dict):\n        for k, v in d.items():\n            assert isinstance(v, (datetime.date, datetime.datetime)), f\"{p}: date.{k} not a date\"\n","typeGuard":"def all_dates_are_datetimes(date_dict):\n    return all(isinstance(v, datetime) for v in date_dict.values())\n","tryCatchPattern":"try:\n    mkdocs.commands.build(config)\nexcept ValidationError as e:\n    if \"Expected type\" in str(e):\n        log.error(f\"Use ISO dates in the date dictionary: {e}\")\n    raise\n","preventionTips":["Write date values unquoted in ISO 8601 format (YYYY-MM-DD)","Never put placeholder strings like 'TBD' or 'soon' inside the date dictionary","Test front-matter changes locally with a build before pushing"],"tags":["mkdocs","blog-plugin","type-error","date","validation"],"backgroundTag":"invalid-date-format","analyzedSha":"e2136532f40aed98af1f6497c0cc6a3cff9f759b","analyzedAt":"2026-08-29T11:20:04.299Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}