Skip to content

HDXDSYS-1629 Add HDXErrorManager subclass of ErrorManager to HDX Pyth… #184

HDXDSYS-1629 Add HDXErrorManager subclass of ErrorManager to HDX Pyth…

HDXDSYS-1629 Add HDXErrorManager subclass of ErrorManager to HDX Pyth… #184

GitHub Actions / Test Results failed Jan 12, 2025 in 0s

1 fail, 138 pass in 1m 12s

139 tests  +1   138 ✅ ±0   1m 12s ⏱️ -11s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     1 ❌ +1 

Results for commit 76d76cb. ± Comparison against earlier commit c13ff6c.

Annotations

Check warning on line 0 in tests.hdx.api.test_ckan.TestCKAN

See this annotation in the file changed.

@github-actions github-actions / Test Results

test_create_dataset (tests.hdx.api.test_ckan.TestCKAN) failed

test-results.xml [took 37s]
Raw output
hdx.data.hdxobject.HDXError: Failed when trying to create hdx_python_api_test! (POST)
self = {'name': 'hdx_python_api_test', 'title': 'HDX Python API test', 'license_id': 'cc-by-sa', 'notes': 'Some notes.', 'cav...'resource_type': 'api', 'url_type': 'api'}], 'updated_by_script': 'hdx_python_api_ignore (2025-01-12T19:52:58.288959)'}
action = 'create'
data = {'caveats': 'None', 'data_update_frequency': '7', 'dataset_date': '[2025-01-12T00:00:00 TO 2025-01-12T00:00:00]', 'dataset_source': 'Someone', ...}
id_field_name = 'name', files_to_upload = {}

    def _write_to_hdx(
        self,
        action: str,
        data: Dict,
        id_field_name: str = None,
        files_to_upload: Dict = {},
    ) -> Union[Dict, List]:
        """Creates or updates an HDX object in HDX and return HDX object metadata dict
    
        Args:
            action (str): Action to perform eg. 'create', 'update'
            data (Dict): Data to write to HDX
            id_field_name (Optional[str]): Name of field containing HDX object identifier. Defaults to None.
            files_to_upload (Dict): Files to upload to HDX
    
        Returns:
            Union[Dict,List]: HDX object metadata
        """
        try:
            for key, value in files_to_upload.items():
                files_to_upload[key] = open(value, "rb")
>           return self.configuration.call_remoteckan(
                self.actions()[action], data, files=files_to_upload
            )

src/hdx/data/hdxobject.py:401: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/hdx/api/configuration.py:388: in call_remoteckan
    return self.remoteckan().call_action(*args, **kwargs)
../../../.local/share/hatch/env/virtual/hdx-python-api/YYawAnFr/hatch-test.py3.12/lib/python3.12/site-packages/ckanapi/remoteckan.py:97: in call_action
    return reverse_apicontroller_action(url, status, response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

url = 'https://demo.data-humdata-org.ahconu.org/api/action/package_create'
status = 409
response = '{"help": "https://demo.data-humdata-org.ahconu.org/api/3/action/help_show?name=package_create", "error": {"tags": [{"vocabulary_id": ["Tag vocabulary was not found."]}], "__type": "Validation Error"}, "success": false}'

    def reverse_apicontroller_action(url, status, response):
        """
        Make an API call look like a direct action call by reversing the
        exception -> HTTP response translation that ApiController.action does
        """
        try:
            parsed = json.loads(response)
            if parsed.get('success'):
                return parsed['result']
            if hasattr(parsed, 'get'):
                err = parsed.get('error', {})
            else:
                err = {}
        except (AttributeError, ValueError):
            err = {}
    
        if not isinstance(err, dict):  # possibly a Socrata API.
            raise ServerIncompatibleError(repr([url, status, response]))
    
        etype = err.get('__type')
        emessage = err.get('message', '')
        if hasattr(emessage, 'split'):
            emessage = emessage.split(': ', 1)[-1]
        if etype == 'Search Query Error':
            # I refuse to eval(emessage), even if it would be more correct
            raise SearchQueryError(emessage)
        elif etype == 'Search Error':
            # I refuse to eval(emessage), even if it would be more correct
            raise SearchError(emessage)
        elif etype == 'Search Index Error':
            raise SearchIndexError(emessage)
        elif etype == 'Validation Error':
>           raise ValidationError(err)
E           ckanapi.errors.ValidationError: {'tags': [{'vocabulary_id': ['Tag vocabulary was not found.']}], '__type': 'Validation Error'}

../../../.local/share/hatch/env/virtual/hdx-python-api/YYawAnFr/hatch-test.py3.12/lib/python3.12/site-packages/ckanapi/common.py:127: ValidationError

The above exception was the direct cause of the following exception:

self = <test_ckan.TestCKAN object at 0x7f15b1dcbf80>
datasetmetadata = 'tests/fixtures/CKAN/hdx_dataset_static.yaml'
testdata = 'tests/fixtures/test_data.csv'
setup_teardown_folder = (<gspread.client.Client object at 0x7f15b12249b0>, '1dst39MEfB5PbjEkRiqjGQz5-CPHCJ4rU')
params = {'corpora': 'teamDrive', 'includeItemsFromAllDrives': True, 'supportsAllDrives': True, 'teamDriveId': '0AKCBfHI3H-hcUk9PVA'}

    def test_create_dataset(
        self,
        datasetmetadata,
        testdata,
        setup_teardown_folder,
        params,
    ):
        today = now_utc()
        gclient, folderid = setup_teardown_folder
    
        def create_gsheet(name, update):
            payload = {
                "name": name,
                "mimeType": "application/vnd.google-apps.spreadsheet",
                "parents": [folderid],
            }
            r = gclient.http_client.request(
                "post", DRIVE_FILES_API_V3_URL, json=payload, params=params
            )
            spreadsheetid = r.json()["id"]
            gsheet = gclient.open_by_key(spreadsheetid)
            wks = gsheet.sheet1
            wks.update(update, "A1")
            gsheet.share("", role="reader", perm_type="anyone")
            return wks, f"{gsheet.url}/export?format=xlsx"
    
        name = "hdx_python_api_test"
        dataset = Dataset.read_from_hdx(name)
        if dataset:
            dataset.delete_from_hdx()
        title = "HDX Python API test"
        dataset = Dataset({"name": name, "title": title})
        dataset.update_from_yaml(datasetmetadata)
        maintainer_id = "196196be-6037-4488-8b71-d786adf4c081"
        dataset.set_maintainer(maintainer_id)
        dataset.set_organization("5a63012e-6c41-420c-8c33-e84b277fdc90")
        dataset.set_time_period(today)
        dataset.set_expected_update_frequency("Every week")
        dataset.set_subnational(True)
        countryiso3s = ["AFG", "PSE", "SYR", "YEM"]
        dataset.add_country_locations(countryiso3s)
        tags = ["conflict-violence", "displacement", "hxl"]
        dataset.add_tags(tags)
        resource_no = 0
    
        def create_resource():
            nonlocal resource_no
    
            resource = Resource(
                {
                    "name": f"test_resource_{resource_no}",
                    "description": f"Test Resource {resource_no}",
                    "last_modified": today.replace(tzinfo=None).isoformat(),
                }
            )
            filestore = resource_no % 2 == 0
            if filestore:
                resource.set_format("csv")
                resource.set_file_to_upload(testdata)
            else:
                wks, url = create_gsheet(
                    "resource1",
                    [[random.random() for i in range(10)] for j in range(10)],
                )
                resource.set_format("xlsx")
                resource["url"] = url
    
            resource_no += 1
            dataset.add_update_resource(resource)
    
        # add resources
        for i in range(10):
            create_resource()
    
>       dataset.create_in_hdx(
            hxl_update=False, updated_by_script="hdx_python_api_ignore"
        )

tests/hdx/api/test_ckan.py:174: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/hdx/data/dataset.py:1144: in create_in_hdx
    self._hdx_update("dataset", "name", force_active=True, **kwargs)
src/hdx/data/hdxobject.py:302: in _hdx_update
    self._save_to_hdx(
src/hdx/data/hdxobject.py:439: in _save_to_hdx
    result = self._write_to_hdx(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {'name': 'hdx_python_api_test', 'title': 'HDX Python API test', 'license_id': 'cc-by-sa', 'notes': 'Some notes.', 'cav...'resource_type': 'api', 'url_type': 'api'}], 'updated_by_script': 'hdx_python_api_ignore (2025-01-12T19:52:58.288959)'}
action = 'create'
data = {'caveats': 'None', 'data_update_frequency': '7', 'dataset_date': '[2025-01-12T00:00:00 TO 2025-01-12T00:00:00]', 'dataset_source': 'Someone', ...}
id_field_name = 'name', files_to_upload = {}

    def _write_to_hdx(
        self,
        action: str,
        data: Dict,
        id_field_name: str = None,
        files_to_upload: Dict = {},
    ) -> Union[Dict, List]:
        """Creates or updates an HDX object in HDX and return HDX object metadata dict
    
        Args:
            action (str): Action to perform eg. 'create', 'update'
            data (Dict): Data to write to HDX
            id_field_name (Optional[str]): Name of field containing HDX object identifier. Defaults to None.
            files_to_upload (Dict): Files to upload to HDX
    
        Returns:
            Union[Dict,List]: HDX object metadata
        """
        try:
            for key, value in files_to_upload.items():
                files_to_upload[key] = open(value, "rb")
            return self.configuration.call_remoteckan(
                self.actions()[action], data, files=files_to_upload
            )
        except Exception as e:
            if id_field_name:
                idstr = f" {data[id_field_name]}"
            else:
                idstr = ""
>           raise HDXError(
                f"Failed when trying to {action}{idstr}! (POST)"
            ) from e
E           hdx.data.hdxobject.HDXError: Failed when trying to create hdx_python_api_test! (POST)

src/hdx/data/hdxobject.py:409: HDXError

Check notice on line 0 in .github

See this annotation in the file changed.

@github-actions github-actions / Test Results

139 tests found

There are 139 tests, see "Raw output" for the full list of tests.
Raw output
tests.hdx.api.test_ckan.TestCKAN ‑ test_create_dataset
tests.hdx.api.test_configuration.TestConfiguration ‑ test_create_set_configuration
tests.hdx.api.test_configuration.TestConfiguration ‑ test_env_vars
tests.hdx.api.test_configuration.TestConfiguration ‑ test_get_hdx_key_site
tests.hdx.api.test_configuration.TestConfiguration ‑ test_hdx_configuration_dict
tests.hdx.api.test_configuration.TestConfiguration ‑ test_hdx_configuration_json
tests.hdx.api.test_configuration.TestConfiguration ‑ test_hdx_configuration_yaml
tests.hdx.api.test_configuration.TestConfiguration ‑ test_init
tests.hdx.api.test_configuration.TestConfiguration ‑ test_project_configuration_dict
tests.hdx.api.test_configuration.TestConfiguration ‑ test_project_configuration_json
tests.hdx.api.test_configuration.TestConfiguration ‑ test_project_configuration_yaml
tests.hdx.api.test_configuration.TestConfiguration ‑ test_remoteckan_validlocations
tests.hdx.api.test_configuration.TestConfiguration ‑ test_set_hdx_key_value
tests.hdx.api.test_configuration.TestConfiguration ‑ test_user_agent
tests.hdx.api.test_locations.TestHDXLocations ‑ test_validlocations
tests.hdx.data.test_dataset_add_hapi_error.TestDatasetAddHAPIError ‑ test_add_hapi_error
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_add_update_delete_resources
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_autocomplete
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_create_in_hdx
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_delete_from_hdx
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_get_all_dataset_names
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_get_all_datasets
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_get_all_resources
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_hdxconnect
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_read_from_hdx
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_reorder_resources
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_revise
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_search_in_hdx
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_update_in_hdx
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_update_json
tests.hdx.data.test_dataset_core.TestDatasetCore ‑ test_update_yaml
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_add_clean_tags
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_add_update_delete_showcase
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_generate_resource_view
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_add_location
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_add_tags
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_api_url
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_hdx_url
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_name_or_id
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_set_date_of_dataset
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_get_set_expected_update_frequency
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_is_set_subnational
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_load_save_to_json
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_maintainer
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_organization
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_quickcharts_resource_last
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_remove_dates_from_title
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_set_dataset_year_range
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_set_quickchart_resource
tests.hdx.data.test_dataset_noncore.TestDatasetNoncore ‑ test_transform_update_frequency
tests.hdx.data.test_dataset_resource_generation.TestDatasetResourceGeneration ‑ test_download_and_generate_resource
tests.hdx.data.test_dataset_resource_generation.TestDatasetResourceGeneration ‑ test_generate_qc_resource_from_rows
tests.hdx.data.test_organization.TestOrganization ‑ test_autocomplete
tests.hdx.data.test_organization.TestOrganization ‑ test_create_in_hdx
tests.hdx.data.test_organization.TestOrganization ‑ test_delete_from_hdx
tests.hdx.data.test_organization.TestOrganization ‑ test_get_all_organizations
tests.hdx.data.test_organization.TestOrganization ‑ test_get_datasets
tests.hdx.data.test_organization.TestOrganization ‑ test_read_from_hdx
tests.hdx.data.test_organization.TestOrganization ‑ test_update_in_hdx
tests.hdx.data.test_organization.TestOrganization ‑ test_update_json
tests.hdx.data.test_organization.TestOrganization ‑ test_update_yaml
tests.hdx.data.test_organization.TestOrganization ‑ test_users
tests.hdx.data.test_resource.TestResource ‑ test_check_required_fields
tests.hdx.data.test_resource.TestResource ‑ test_check_url_filetoupload
tests.hdx.data.test_resource.TestResource ‑ test_create_in_hdx
tests.hdx.data.test_resource.TestResource ‑ test_datastore
tests.hdx.data.test_resource.TestResource ‑ test_date_data_updated
tests.hdx.data.test_resource.TestResource ‑ test_delete_from_hdx
tests.hdx.data.test_resource.TestResource ‑ test_download
tests.hdx.data.test_resource.TestResource ‑ test_get_api_url
tests.hdx.data.test_resource.TestResource ‑ test_get_dataset
tests.hdx.data.test_resource.TestResource ‑ test_get_hdx_url
tests.hdx.data.test_resource.TestResource ‑ test_get_set_date_of_resource
tests.hdx.data.test_resource.TestResource ‑ test_mark_broken
tests.hdx.data.test_resource.TestResource ‑ test_patch
tests.hdx.data.test_resource.TestResource ‑ test_read_from_hdx
tests.hdx.data.test_resource.TestResource ‑ test_resource_views
tests.hdx.data.test_resource.TestResource ‑ test_search_in_hdx
tests.hdx.data.test_resource.TestResource ‑ test_update_in_hdx
tests.hdx.data.test_resource.TestResource ‑ test_update_json
tests.hdx.data.test_resource.TestResource ‑ test_update_yaml
tests.hdx.data.test_resource_view.TestResourceView ‑ test_copy
tests.hdx.data.test_resource_view.TestResourceView ‑ test_create_in_hdx
tests.hdx.data.test_resource_view.TestResourceView ‑ test_delete_from_hdx
tests.hdx.data.test_resource_view.TestResourceView ‑ test_get_all_for_resource
tests.hdx.data.test_resource_view.TestResourceView ‑ test_read_from_hdx
tests.hdx.data.test_resource_view.TestResourceView ‑ test_update_in_hdx
tests.hdx.data.test_resource_view.TestResourceView ‑ test_update_json
tests.hdx.data.test_resource_view.TestResourceView ‑ test_update_yaml
tests.hdx.data.test_showcase.TestShowcase ‑ test_create_in_hdx
tests.hdx.data.test_showcase.TestShowcase ‑ test_datasets
tests.hdx.data.test_showcase.TestShowcase ‑ test_delete_from_hdx
tests.hdx.data.test_showcase.TestShowcase ‑ test_get_all_showcases
tests.hdx.data.test_showcase.TestShowcase ‑ test_read_from_hdx
tests.hdx.data.test_showcase.TestShowcase ‑ test_search_in_hdx
tests.hdx.data.test_showcase.TestShowcase ‑ test_tags
tests.hdx.data.test_showcase.TestShowcase ‑ test_update_in_hdx
tests.hdx.data.test_showcase.TestShowcase ‑ test_update_json
tests.hdx.data.test_showcase.TestShowcase ‑ test_update_yaml
tests.hdx.data.test_update_dataset_resources.TestUpdateDatasetResourcesLogic ‑ test_dataset_update_resources
tests.hdx.data.test_update_logic.TestUpdateLogic ‑ test_update_logic_1
tests.hdx.data.test_update_logic.TestUpdateLogic ‑ test_update_logic_2
tests.hdx.data.test_update_logic.TestUpdateLogic ‑ test_update_logic_3
tests.hdx.data.test_user.TestUser ‑ test_autocomplete
tests.hdx.data.test_user.TestUser ‑ test_create_in_hdx
tests.hdx.data.test_user.TestUser ‑ test_delete_from_hdx
tests.hdx.data.test_user.TestUser ‑ test_get_all_users
tests.hdx.data.test_user.TestUser ‑ test_get_organizations
tests.hdx.data.test_user.TestUser ‑ test_get_organizations_invalid_user
tests.hdx.data.test_user.TestUser ‑ test_get_token_list
tests.hdx.data.test_user.TestUser ‑ test_read_from_hdx
tests.hdx.data.test_user.TestUser ‑ test_update_in_hdx
tests.hdx.data.test_user.TestUser ‑ test_update_json
tests.hdx.data.test_user.TestUser ‑ test_update_yaml
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_autocomplete
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_chainrule_error
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_create_approved_vocabulary
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_create_in_hdx
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_delete_approved_vocabulary
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_delete_from_hdx
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_get_all_vocabularies
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_get_approved_vocabulary
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_init
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_read_from_hdx
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_tag_mappings
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_tags
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_update_approved_vocabulary
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_update_in_hdx
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_update_json
tests.hdx.data.test_vocabulary.TestVocabulary ‑ test_update_yaml
tests.hdx.facades.test_infer_arguments.TestInferArguments ‑ test_facade
tests.hdx.facades.test_keyword_arguments.TestKeywordArguments ‑ test_exception
tests.hdx.facades.test_keyword_arguments.TestKeywordArguments ‑ test_facade
tests.hdx.facades.test_simple.TestSimple ‑ test_exception
tests.hdx.facades.test_simple.TestSimple ‑ test_facade
tests.hdx.utilities.test_dataset_title_helper.TestDatasetTitleHelper ‑ test_fuzzy_match_dates_in_title
tests.hdx.utilities.test_dataset_title_helper.TestDatasetTitleHelper ‑ test_get_date_from_title
tests.hdx.utilities.test_filestore_helper.TestFilestoreHelper ‑ test_dataset_update_filestore_resource
tests.hdx.utilities.test_hdx_error_handler.TestHDXErrorHandler ‑ test_hdx_error_handler