GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DISCUSSION PR: Re-writing Entity to subclass object instead of dict. by dhermes · Pull Request #445 · googleapis/google-cloud-python

Conversation

@dhermes

@dhermes dhermes commented Dec 19, 2014

Copy link
Copy Markdown
Contributor

This fixes #396, but I am happy to close it if there are issues with it. (Hence the DISCUSSION in the description.)

It is a first-step towards the discussion in #336 with @elibixby and @proppy.

The Entity class doesn't attempt to be a dictionary, rather it provides __getitem__ (and set and del) semantics and update_properties and clear_properties methods for updating the properties and leaving the rest of the entity alone.

The long term goal is to provide a way to do something like:

>>> e1 = Entity('SomeKind', 1, prop1=u'foo', prop2=u'bar')
>>> e1
<Entity[{'kind': 'SomeKind', 'id': 1}] {'prop1': u'foo', 'prop2': u'bar'}>
>>> e2 = Entity('SomeKind', 1, {'prop1': u'foo', 'prop2': u'bar'})
>>> e2
<Entity[{'kind': 'SomeKind', 'id': 1}] {'prop1': u'foo', 'prop2': u'bar'}>
>>> e1 == e2
True
>>> e_partial = Entity('ParentKind', 1, 'ChildKind', prop=True)
>>> e_partial
<Entity[{'kind': 'Parent', 'id': 1}, {'kind': 'Child'}] {'prop': True}>

and I think to get there this is necessary to separate the property data (as _data) from the other metadata.

I am still trying to figure out a way to squeeze in "special" keyword arguments like

  • key (may be possible to just implement a method like key.to_args() so we don't need a kwarg. Or instead we could check if len(positional_args) == 1 and isinstance(positional_args[0], Key))
  • dataset (Implicit dataset from environ #444 may make this unnecessary if we take it a bit further and my design doc just says forget about it and set it on the key. Though the ID is still needed if we only have the key parts from positional_args.)
  • exclude_from_indexes (as a power-user feature, it may not be necessary to put this in the constructor)

but that is outside the scope of this PR / discussion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@coveralls

coveralls commented Dec 19, 2014

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling c1137f6 on dhermes:do-not-inherit-dict into 21e5f45 on GoogleCloudPlatform:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes dhermes mentioned this pull request Dec 19, 2014
datastore.Entity should not know about the dataset #446
Closed
@elibixby

elibixby commented Dec 19, 2014

Copy link
Copy Markdown

Give the discussion in #446, it seems that syntax should actually be Entity(Key('SomeKind',1), ...) in which case I think Entity(key, props) makes more sense than Entity(key, **props). This also allows for easy addition of other special kwargs (although as per the design doc I think the only necessary one is exclude_from_indexes).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Dec 19, 2014

Copy link
Copy Markdown
Contributor Author

First, let me note that my trailing comments give a context for this PR, but don't actually pertain to the code in the PR.


To address @elibixby remarks:

Yes #444 needs to be implemented for

Entity('Kind', 1, prop1=u'foo')

to have a chance of working.

I think in addition to the constructors I mentioned above we should also enable

>>> key
<Key[{'kind': 'SomeKind', 'id': 1}]>
>>> Entity(key, prop1=u'foo', prop2=u'bar')
<Entity[{'kind': 'SomeKind', 'id': 1}] {'prop1': u'foo', 'prop2': u'bar'}>
>>> Entity(key, {'prop1': u'foo', 'prop2': u'bar'})
<Entity[{'kind': 'SomeKind', 'id': 1}] {'prop1': u'foo', 'prop2': u'bar'}>

This will allow for things like keys from multiple datasets in the same application and keys with namespaces.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@elibixby

elibixby commented Dec 19, 2014

Copy link
Copy Markdown

Is this providing too many ways to achieve the same thing? I do like the idea of being able to instantiate an entity with a path (and providing the key with the "default" dataset from the environment), but I'm not sure if Entity(key, dict(prop1=u'foo', prop2=u'bar')) is much more burdensome than Entity(key, prop1=u'foo', prop2=u'bar'). If both exist, then users must remember to pass a dict rather than kwargs when setting exclude_from_indexes (or any meta-properties that may crop up in the future)

Just a my $.02. I think the ideas have been fantastic so far, and am really excited with all the discussion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Dec 19, 2014

Copy link
Copy Markdown
Contributor Author

@elibixby You're probably right that we should only accept a key as a positional arg since the syntax would be the same.

RE: exclude_from_indexes I'm fine with

>>> e = Entity(key, prop1=u'foo', prop2=u'bar')
>>> e.remove_prop_from_index('prop1')

A full-blown ORM (like ndb) makes this easier when Propertys are objects:

class Foo(ndb.Model):
    bar = ndb.StringProperty(indexed=False)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@elibixby

elibixby commented Dec 19, 2014

Copy link
Copy Markdown

Yes! I like that!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes
dhermes force-pushed the do-not-inherit-dict branch from c1137f6 to 0d79df0 Compare December 19, 2014 20:13
@coveralls

coveralls commented Dec 19, 2014

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 0d79df0 on dhermes:do-not-inherit-dict into * on GoogleCloudPlatform:master*.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes
Re-writing Entity to subclass object instead of dict.
e43096a
@dhermes
dhermes force-pushed the do-not-inherit-dict branch from 0d79df0 to e43096a Compare December 20, 2014 01:44
@coveralls

coveralls commented Dec 20, 2014

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling e43096a on dhermes:do-not-inherit-dict into b343acf on GoogleCloudPlatform:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Dec 21, 2014
Fix 3 and 451 #454
Closed
Address first part of 451: Remove Key.from_path #456
Merged
tseaver
tseaver reviewed Dec 23, 2014
View reviewed changes
Comment thread gcloud/datastore/entity.py

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Dec 23, 2014

Copy link
Copy Markdown
Contributor

Overall, I don't see any advantage to the "object-with-a-dict" versus "object-derived-from-dict".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Dec 23, 2014

Copy link
Copy Markdown
Contributor Author

@tseaver let's forget about this for now. I initially did it because I didn't want a split MRO on Entity but it won't matter in the long-run since Entity won't need a dataset.

In the interest of "only one way", the note above for me is the best option for a constructor. (First positional arg must be a key, if more than one, second must be a dict. Otherwise, kwargs acts as the dict.)

I'll rebase #456 to forget about this PR and we'll go from there (after wrapping up #444).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes dhermes closed this Dec 23, 2014
@dhermes

dhermes commented Dec 23, 2014

Copy link
Copy Markdown
Contributor Author

Closing PR but leaving the branch alive in my fork so may revisit. It likely won't be necessary as Entity gets stripped down further.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes dhermes mentioned this pull request Dec 30, 2014
Address sixth part of 451: Implement Key.compare_to_proto to check pb keys against existing. #462
Merged
@dhermes
dhermes deleted the do-not-inherit-dict branch January 7, 2015 03:04
@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Dec 31, 2015
tseaver added a commit that referenced this pull request Jun 25, 2018
@tseaver
Add blob properties to support retention policy feature. (#446)
f6048da
Toward #445.
tseaver added a commit that referenced this pull request Jun 25, 2018
@tseaver
Add bucket properties to support retention policy feature. (#447)
6a1866e
Toward #445.
tseaver added a commit that referenced this pull request Jun 25, 2018
@tseaver
Add 'Bucket.lock_retention_policy' API wrapper. (#448)
80129f1
Toward #445.
tseaver added a commit that referenced this pull request Aug 28, 2018
@tseaver
Add blob properties to support retention policy feature. (#446)
cee0807
Toward #445.
tseaver added a commit that referenced this pull request Aug 28, 2018
@tseaver
Add bucket properties to support retention policy feature. (#447)
bf18051
Toward #445.
tseaver added a commit that referenced this pull request Aug 28, 2018
@tseaver
Add 'Bucket.lock_retention_policy' API wrapper. (#448)
635e247
Toward #445.
tseaver added a commit that referenced this pull request Sep 7, 2018
@tseaver
Add blob properties to support retention policy feature. (#446)
c29729e
Toward #445.
tseaver added a commit that referenced this pull request Sep 7, 2018
@tseaver
Add bucket properties to support retention policy feature. (#447)
3c7054e
Toward #445.
tseaver added a commit that referenced this pull request Sep 7, 2018
@tseaver
Add 'Bucket.lock_retention_policy' API wrapper. (#448)
2f22ae1
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add blob properties to support retention policy feature. (#446)
3060050
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add bucket properties to support retention policy feature. (#447)
b03b6fe
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add 'Bucket.lock_retention_policy' API wrapper. (#448)
16d7da0
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add blob properties to support retention policy feature. (#446)
108c557
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add bucket properties to support retention policy feature. (#447)
b7a1566
Toward #445.
tseaver added a commit that referenced this pull request Sep 17, 2018
@tseaver
Add 'Bucket.lock_retention_policy' API wrapper. (#448)
8bead37
Toward #445.
parthea pushed a commit that referenced this pull request Jun 4, 2023
@release-please
chore(main): release 2.8.0 (#445)
2442a0f
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Jun 4, 2023
@gcf-owl-bot
chore(python): update release script dependencies (#445)
1c706c4
Source-Link: googleapis/synthtool@25083af
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e6cbd61f1838d9ff6a31436dfc13717f372a7482a82fc1863ca954ec47bff8c8

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Jun 4, 2023
@gcf-owl-bot
docs: Fix formatting of request arg in docstring (#445)
62a476c
* docs: Fix formatting of request arg in docstring

chore: Update gapic-generator-python to v1.9.1
PiperOrigin-RevId: 518604533

Source-Link: googleapis/googleapis@8a085ae

Source-Link: googleapis/googleapis-gen@b2ab4b0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjJhYjRiMGEwYWUyOTA3ZTgxMmMyMDkxOThhNzRlMDg5OGFmY2IwNCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Sep 22, 2023
@gcf-owl-bot
docs: minor comment update (#445)
336a994
* docs: minor comment update

PiperOrigin-RevId: 512725339

Source-Link: googleapis/googleapis@ea8d826

Source-Link: googleapis/googleapis-gen@dc453f7
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZGM0NTNmNzcwMmNkNGQzOThmZTU3NzMxMTgwNGFlYTFhZDIwNTFkYSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Sep 22, 2023
@gcf-owl-bot
chore(python): allow client documentation to be customized in README (#…
90dfc0c
…445)

Source-Link: googleapis/synthtool@95d9289
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:c8878270182edaab99f2927969d4f700c3af265accd472c3425deedff2b7fd93

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Oct 21, 2023
@gcf-owl-bot
chore: add prerelease nox session (#445)
8a0439a
Source-Link: googleapis/synthtool@050953d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:65e656411895bff71cffcae97246966460160028f253c2e45b7a25d805a5b142

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Oct 21, 2023
@renovate-bot @gcf-owl-bot @parthea
chore(deps): update all dependencies (#445)
2991885
* chore(deps): update all dependencies

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* revert

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Oct 21, 2023
@gcf-owl-bot
chore: Bump gapic-generator-python version to 1.3.0 (#445)
613e308
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 472561635

Source-Link: googleapis/googleapis@332ecf5

Source-Link: googleapis/googleapis-gen@4313d68
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDMxM2Q2ODI4ODBmZDlkNzI0NzI5MTE2NGQ0ZTlkM2Q1YmQ5ZjE3NyJ9
parthea pushed a commit that referenced this pull request Oct 21, 2023
@release-please
chore(main): release 2.8.3 (#445)
32e17c2
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Aug 21, 2025
@renovate-bot
chore(deps): update dependency pytest to v7.1.2 (#445)
8eb55d8
parthea pushed a commit that referenced this pull request Sep 16, 2025
@renovate-bot @parthea
chore(deps): update dependency pytest to v7.1.2 (#445)
1d80b4b
parthea pushed a commit that referenced this pull request Sep 18, 2025
@tswast
feat!: use nullable Int64 and boolean dtypes if available (#445)
732b4de
* feat: use nullable Int64 and boolean dtypes if available

* allow google-cloud-bigquery 3.x

* document dtypes mapping
parthea pushed a commit that referenced this pull request Sep 18, 2025
@release-please
chore(main): release 0.17.0 (#472)
8a5066c
🤖 I have created a release *beep* *boop*
---


## [0.17.0](googleapis/python-bigquery-pandas@v0.16.0...v0.17.0) (2022-01-19)


### ⚠ BREAKING CHANGES

* use nullable Int64 and boolean dtypes if available (#445)

### Features

* accepts a table ID, which downloads the table without a query ([#443](googleapis/python-bigquery-pandas#443)) ([bf0e863](googleapis/python-bigquery-pandas@bf0e863))
* use nullable Int64 and boolean dtypes if available ([#445](googleapis/python-bigquery-pandas#445)) ([89078f8](googleapis/python-bigquery-pandas@89078f8))


### Bug Fixes

* `read_gbq` supports extreme DATETIME values such as `0001-01-01 00:00:00` ([#444](googleapis/python-bigquery-pandas#444)) ([d120f8f](googleapis/python-bigquery-pandas@d120f8f))
* `to_gbq` allows strings for DATE and floats for NUMERIC with `api_method="load_parquet"` ([#423](googleapis/python-bigquery-pandas#423)) ([2180836](googleapis/python-bigquery-pandas@2180836))
* allow extreme DATE values such as `datetime.date(1, 1, 1)` in `load_gbq` ([#442](googleapis/python-bigquery-pandas#442)) ([e13abaf](googleapis/python-bigquery-pandas@e13abaf))
* avoid iteritems deprecation in pandas prerelease ([#469](googleapis/python-bigquery-pandas#469)) ([7379cdc](googleapis/python-bigquery-pandas@7379cdc))
* use data project for destination in `to_gbq` ([#455](googleapis/python-bigquery-pandas#455)) ([891a00c](googleapis/python-bigquery-pandas@891a00c))


### Miscellaneous Chores

* release 0.17.0 ([#470](googleapis/python-bigquery-pandas#470)) ([29ac8c3](googleapis/python-bigquery-pandas@29ac8c3))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
parthea pushed a commit that referenced this pull request Nov 22, 2025
@crwilcox @gcf-owl-bot
test: address issue with fixtures and emulator (#445)
2243664
* test: address issue with fixtures not raising exceptions under emulator, flag tests as not emulator compatible

* test: modify not_in_emulator to skip_on_emulator

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Nov 24, 2025
@miraleung @software-dov
fix: handle repeated fields in method signatures (#445)
79e5615
Co-authored-by: Dov Shlachter <[email protected]>
parthea pushed a commit that referenced this pull request Nov 24, 2025
@youcandanch
chore: use pytest-flake8==1.1.0 in dev_requirements.txt (#446)
80c10ff
#### Summary

`dev_requirements.txt` was recently changed to upgrade the dependency on pytest-flake8 from 1.1.0 to 1.1.1. Unfortunately, pytest-flake8 requires pytest 7 or above, and the current pinned dependency for pytest is 6.2.5. I tried moving up to pytest 7 but it seems like there's a decent amount of work going into that, so in order to fix main, this PR moves the pytest-flake8 pinned version back to 1.1.0.

Fixes #445.
parthea pushed a commit that referenced this pull request Nov 24, 2025
@renovate-bot
chore(deps): update dependency pytest to v7.3.2 (#445)
ff80597
parthea added a commit that referenced this pull request Mar 2, 2026
@gcf-owl-bot @parthea
chore(python): use python 3.10 for docs build (#445)
5bdc76d
* chore(python): use python 3.10 for docs build

Source-Link: googleapis/synthtool@9ae0785
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:52210e0e0559f5ea8c52be148b33504022e1faef4e95fbe4b32d68022af2fa7e

* use python 3.10 for docs build

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Mar 6, 2026
@timgraham @odeke-em
django: remove SchemaEditor.quote_value() TODO (#445)
05f3fb9
fixes #227

Co-authored-by: Emmanuel T Odeke <[email protected]>
parthea pushed a commit that referenced this pull request Mar 9, 2026
@renovate-bot
chore(deps): update dependency nox to v2022.11.21 (#445)
c92f8c4
parthea pushed a commit that referenced this pull request Mar 9, 2026
@cojenco
fix: add ConnectionError to default retry (#445)
a5c15b2
This adds python built-in [ConnectionError](https://docs.python.org/3/library/exceptions.html#ConnectionError) to default retryable types. 
ConnectionError was recently added in the [BigQuery library](googleapis/python-bigquery#571) to allow retries. 

Fixes #426 🦕
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: datastore Issues related to the Datastore API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Custom classes inheriting Entity cannot be constructed from entities

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@dhermes @coveralls @elibixby @tseaver
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.