Skip to content

pathlib and Django v3.1 Compatibility #501

Closed
@AashishDhakal

Description

@AashishDhakal
  • Operating System version: Windows 10 home single language
  • Firebase SDK version: _____
  • Library version: 4.4.0
  • Firebase Product: auth

Recently with Django 3.1 release, the previous os.path library was removed and pathlib is introduced for maintaining the file paths. The class type returned by os.path is str while pathlib returns its own pathlib.Path class type.

This raises ValueError even if the path is correct using pathlib and if we do it using the os.path library it works fine.

ValueError: Invalid certificate argument. Certificate argument must be a file path, or a dict containing th
e parsed file contents.

So, to reproduce this I figured out two ways:

  1. Explicit typecasting of the path argument.
credentials.Certificate(str(path_to_json))
  1. Some tweaks into the credentials.py file to accept pathlib object as well.
if isinstance(cert, str) or isinstance(cert, pathlib.Path):
            with open(cert) as json_file:
                json_data = json.load(json_file)
        elif isinstance(cert, dict):
            json_data = cert
        else:
            raise ValueError(
                'Invalid certificate argument: "{0}". Certificate argument must be a file path, '
                'or a dict containing the parsed file contents.'.format(cert))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions