Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription creation without pre-existing schedule item fails (user error?) #1543

Open
CodingOnWindowsOS opened this issue Dec 7, 2024 · 3 comments

Comments

@CodingOnWindowsOS
Copy link

Describe the bug
I am attempting to create a subscription to a workbook using a schedule that doesn't exist at creation time. To perform the same action using Tableau Cloud/Server front-end, the user would configure the subscription by specifying the target type (view or entire workbook), format, subject, and schedule.

Versions
Tableau Cloud
Python 3.12.3
TSC library version 3.24

To Reproduce

 # Sign-in to server.
  with server.auth.sign_in(tableau_auth):
      # Ensure the most recent Tableau REST API version is used.
      server.use_highest_version()
      # Retrieve the user requiring the new subscription.
      user = server.users.filter(name='[email protected]')
      # Retreive the subscription's content (e.g., workbook, view)
      target = server.workbooks.filter(name='North America Sales')

      new_subscription = tsc.SubscriptionItem(
          subject='North America Sales (demo)',
          schedule_id=tsc.ScheduleItem(
              name=None,
              priority=None,
              schedule_type=None,
              execution_order=None,
              interval_item=tsc.DailyInterval(time(0),
                  24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
              )
          ),
          user_id=user[0].id,
          target=tsc.Target(target[0].id, target_type='Workbook')
      )

      # Subscribe the user to the target content.
      server.subscriptions.create(subscription_item=new_subscription)

Results
What are the results or error messages received?
TypeError: cannot serialize <Schedule#None "None" <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>> { _created_at: None, _end_schedule_at: None, _id: None, _next_run_at: None, _state: None, _updated_at: None, interval_item: <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>, _execution_order: None, _name: None, _priority: None, _schedule_type: None} (type ScheduleItem)

If I swap out the subscription item configuration above for the following that uses a pre-existing schedule, then it works fine.

new_subscription = tsc.SubscriptionItem(
    subject='North America Sales (demo)',
    schedule_id='f3dcaf7a-9668-4eb2-8c20-2f7c21e82744',
    user_id=user[0].id,
    target=tsc.Target(target[0].id, target_type='Workbook')
)
@jacalata
Copy link
Contributor

jacalata commented Dec 8, 2024

I believe this is indeed a requirement, but we could return a better error from the server, and tsc should give a hint too.

@CodingOnWindowsOS
Copy link
Author

Thank you for the support!

The odd part is that I can manually create a subscription to the workbook using the front-end features, subsequently query that subscription using TSC, and observe the schedule ID, name, priority, etc. are None for that subscription. The date and time the subscription is configured to fire off is populated, but no schedule ID. That's the behavior I am trying to replicate when creating them using TSC and am at a loss as to why it doesn't work.

I also tried copying the schedule item from a preexisting subscription that I manually configured. It also fails. I'll provide a snippet of the subscription object returned where the schedule ID is not populated and corresponds to the subscription mentioned above tomorrow.

Thanks again!

@CodingOnWindowsOS
Copy link
Author

Manual creation of subscription to workbook.
subscription_image_1
subscription_image_2

Below is the subscription retrieved after creating it manually using the front-end. The manual creation process is shown within the two images.
<Subscription#0f1ab430-5b67-45fa-93f9-e2ee9e465601 subject(Daily Sales (testing)) schedule_id(None) user_id(9390ecd3-2278-467c-a636-5486afd3dec1) target(<Target#5faf8999-1ad8-4f0d-b337-b72a3882a418, Workbook>)

Using subscription.dict:
{'_id': '0f1ab430-5b67-45fa-93f9-e2ee9e465601', '_attach_image': False, '_attach_pdf': True, 'message': 'Testing', 'page_orientation': 'PORTRAIT', 'page_size_option': 'LETTER', 'schedule_id': None, '_send_if_view_empty': True, 'subject': 'Daily Sales (testing)', '_suspended': False, 'target': <Target#5faf8999-1ad8-4f0d-b337-b72a3882a418, Workbook>, 'user_id': '9390ecd3-2278-467c-a636-5486afd3dec1', 'schedule': [<Schedule#None "None" <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>> { _created_at: None, _end_schedule_at: None, _id: None, _next_run_at: None, _state: None, _updated_at: None, interval_item: <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>, _execution_order: None, _name: None, _priority: None, _schedule_type: None}]}

Accessing the schedule attribute of the subscription:
[<Schedule#None "None" <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>> { _created_at: None, _end_schedule_at: None, _id: None, _next_run_at: None, _state: None, _updated_at: None, interval_item: <DailyInterval start=00:00:00 interval=(24.0, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')>, _execution_order: None, _name: None, _priority: None, _schedule_type: None}]

Notice the schedule ID is none as are the vast majority of attributes related to the schedule aside from those necessary for the subscription. I am hoping to achieve the same functionality using TSC. I hope that makes sense! Am I just doing it wrong in my original code example or is something else amiss? @jacalata

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

No branches or pull requests

2 participants