chore: switching out ConnectorRegistry references for DatasourceDAO#20149
chore: switching out ConnectorRegistry references for DatasourceDAO#20149hughhhh wants to merge 25 commits intoapache:masterfrom
Conversation
…uperset into connreg-to-datadao_2
…reg-to-datadao_2
| datasource_type = request.args.get("datasource_type") | ||
| if datasource_id and datasource_type: | ||
| ds_class = ConnectorRegistry.sources.get(datasource_type) | ||
| ds_class = DatasourceDAO.sources.get(datasource_type) |
There was a problem hiding this comment.
use DatasourceType(datasource_type) here
There was a problem hiding this comment.
DatasourceDAO.sources should be able to take either a string or the DatasourceType instance, so I think either works here.
There was a problem hiding this comment.
of course you'll get an error either way if the datasource_type is not valid.
superset/views/core.py
Outdated
| datasource_id, datasource_type = request.args["datasourceKey"].split("__") | ||
| datasource = ConnectorRegistry.get_datasource( | ||
| datasource = DatasourceDAO.get_datasource( | ||
| datasource_type, |
There was a problem hiding this comment.
use DatasourceType(datasource.type)
superset/views/datasource/views.py
Outdated
| database_id = datasource_dict["database"].get("id") | ||
| orm_datasource = ConnectorRegistry.get_datasource( | ||
| orm_datasource = DatasourceDAO.get_datasource( | ||
| datasource_type, datasource_id, db.session |
There was a problem hiding this comment.
use DatasourceType(datasource.type)
| # make temporary change and revert it to refresh the changed_on property | ||
| datasource = ConnectorRegistry.get_datasource( | ||
| datasource = DatasourceDAO.get_datasource( | ||
| datasource_type=payload["datasource"]["type"], |
There was a problem hiding this comment.
use DatasourceType(datasource.type)
|
|
||
| # make temporary change and revert it to refresh the changed_on property | ||
| datasource = ConnectorRegistry.get_datasource( | ||
| datasource = DatasourceDAO.get_datasource( |
There was a problem hiding this comment.
use DatasourceType(datasource.type)
superset/models/dashboard.py
Outdated
| if id_ is None: | ||
| continue | ||
| datasource = ConnectorRegistry.get_datasource_by_id(session, id_) | ||
| # todo(phillip): get datasource type for this method |
| # pylint: disable=import-outside-toplevel | ||
| from superset.datasource.dao import DatasourceDAO | ||
|
|
||
| return DatasourceDAO.sources[self.datasource_type] |
There was a problem hiding this comment.
use DatasourceType(datasource_type)
superset/cachekeys/api.py
Outdated
There was a problem hiding this comment.
update DatasourceType(datasource_type)
c9cd671 to
6a85df3
Compare
66cdb1c to
95c5eb2
Compare
821da1c to
ac2d8aa
Compare
efb667e to
051c26c
Compare
051c26c to
ec17f51
Compare
Decided to move all the functions into the model |
| "owner": owner, | ||
| "datasource_id": datasource_id, | ||
| "datasource_type": datasource_type, | ||
| "datasource_type": DatasourceType(datasource_type), |
There was a problem hiding this comment.
why is this one different from the above one?
There was a problem hiding this comment.
are you referencing this class definition?
https://github.com/apache/superset/pull/20149/files/b678a8ba981f7687c17bc68b4f529209bde2d961#diff-6029cd3077bd4123d18311935a0fef83a580ccf22f4a98b6085ed780fd7257e9R27
There was a problem hiding this comment.
No I am referring to this: https://github.com/apache/superset/pull/20149/files/b678a8ba981f7687c17bc68b4f529209bde2d961#diff-6029cd3077bd4123d18311935a0fef83a580ccf22f4a98b6085ed780fd7257e9R27
THis one has DatasourceType(datasource_type) the version above has DatasourceType
| def get_datasource( | ||
| cls, session: Session, datasource_type: DatasourceType, datasource_id: int | ||
| ) -> Datasource: | ||
| if datasource_type not in cls.sources: |
There was a problem hiding this comment.
I think we're going to want to accept the string value as well here.
I don't think "table" in cls.sources is going to work for example.
There was a problem hiding this comment.
I'm currently casting all the values going into the get_datasource function like this:
DatasourceDAO.get_datasource(
db.session, DatasourceType(datasource["type"]), int(datasource["id"])
)
So moving forward i think we should push for the enums since it's easy to cast via just wrapping it in a DatasourceType() constructor. If we allow string we'd have to add logic to handle/report whenever the user sending us invalid values.
I'm okay with putting the Union[str, DatasourceType] but don't think it takes much work to just wrap the string with the DatasourceType constructor before passing it into the function
There was a problem hiding this comment.
you could also just wrap source = cls.sources[datasource_type] in a try/catch block. I just think there's too much room for error here across the application with people who may not know that they can't pass in a string. This should work if datasource_type is either a string or the enum key.
superset/security/manager.py
Outdated
| set | ||
| ) | ||
| session = self.get_session | ||
| all_datasources = SqlaTable.get_all_sqlatables_datasources(session) |
There was a problem hiding this comment.
nit, but any reason why you wouldn't name this method get_all_datasources?
eschutho
left a comment
There was a problem hiding this comment.
most are small questions, but if datasource_type not in cls.sources: could cause problems if a string is passed in. I personally think we could allow both types, but we could prob go either way. It's just going to be difficult to enforce with typing.
|
|
||
| def get_table_connector_registry() -> Any: | ||
| return ConnectorRegistry.sources["table"] | ||
| return DatasourceDAO.sources[DatasourceType.TABLE] |
There was a problem hiding this comment.
can we use the SqlaTable model directly since this is the only option here?
| cls, session: Session, datasource_type: DatasourceType, datasource_id: int | ||
| ) -> Datasource: | ||
| if datasource_type not in cls.sources: | ||
| raise DatasourceTypeNotSupportedError() |
There was a problem hiding this comment.
notes: set this exception to return 422
|
|
||
| @classmethod | ||
| def get_datasource( | ||
| cls, session: Session, datasource_type: DatasourceType, datasource_id: int |
There was a problem hiding this comment.
go with a Union[str, DatasourceType] and add test to verify works both and will throw 422
|
Moving here #20380 |
SUMMARY
Switching out all references of
ConnectorRegistrytoDatasourceDAO. In the PR, we are focusing on just removing the references and moving towards allowing other Datasources to power charts.One issue is the circular dependencies that are blocking us from fully removing the logic to allow the app to run. So i've moved that code out the
ConnectorRegistryfor now and will prioritize a bigger refactor to stop the import issues in superset moving forward.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION