Skip to content

Conversation

@mnoszczak
Copy link
Contributor

@mnoszczak mnoszczak commented Mar 8, 2023

https://labelbox.atlassian.net/browse/AL-5192

Added support for last_activity_at / label_created_at filters which are transformed into search query params before making GQL call



class ProjectExportFilters(TypedDict):
label_created_at: Optional[Tuple[str, str]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good place to add a docstring to describe each of these filter items in detail, and maybe put the behavior for how we fetch the timezones as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could do a follow up PR with improved docs. At this point we're linking to the docs through URL in export_v2's docstring, which should give good guidance.

I don't want to block the release with the docs.

logger = logging.getLogger(__name__)


def _validate_datetime(string_date: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a utils etc package to move it to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - right now we're using that only in project file scope, I would move it into utils once there's use case outside of that file


def export_v2(self,
task_name: Optional[str] = None,
filters: Optional[ProjectExportFilters] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intend of default = None to allow to pass filters value as None as opposed to just missing variable filters? If not, a default is not required. Also see here https://docs.python.org/3.9/library/typing.html#typing.Optional
PS This seems to be the pattern we have been following, so just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default value is not provided, a function call fails with:

 export_v2() missing 2 required positional arguments: 'task_name' and 'params'

"label_details": False
})

_filters = filters or ProjectExportFilters({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another nitpick, I like to wrap those in a default fun like

class ProjectExportFilters
  @classmethod
  def null_filter():
   self({...})

})

def _get_timezone() -> str:
timezone_query_str = """query CurrentUserPyApi { user { timezone } }"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this is prob more for my own education, but don't we have some sort of sdk-side authenticated user object that should already expose time sone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into the codebase myself and asked @kkim-labelbox about that - looks like we haven't had an use case to fetch timezone before.

}
}

if "last_activity_at" in _filters and _filters[
Copy link
Contributor

@vbrodsky vbrodsky Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if "last_activity_at" in _filters and _filters[
if _filters.get("last_activity_at", None) is not None:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started with that approach, but if I use unsafe getter, mypy will be bothered with this piece:

            values = _filters['last_activity_at']
            start, end = values

Perhaps mypy is not good enough with typings?

Copy link
Contributor

@vbrodsky vbrodsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had some nitpicks and questions

@mnoszczak mnoszczak merged commit 5d05b5c into develop Mar 9, 2023
@mnoszczak mnoszczak deleted the mno/al-5192 branch March 9, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants